Bug 1119199 - Rewrite MaybyOneOf with variadic template.
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 13 Jan 2015 10:48:10 +1100
changeset 223421 aa2eb48a20d9
parent 223420 ea1a96f3a4c0
child 223422 accc4cc9009e
push id53905
push userxquan@mozilla.com
push dateMon, 12 Jan 2015 23:48:49 +0000
treeherdermozilla-inbound@428abebd41a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1119199
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1119199 - Rewrite MaybyOneOf with variadic template.
js/src/jsstr.cpp
mfbt/MaybeOneOf.h
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -756,24 +756,24 @@ ToUpperCase(JSContext *cx, JSLinearStrin
         }
 
         if (resultIsLatin1) {
             Latin1CharPtr buf = cx->make_pod_array<Latin1Char>(length + 1);
             if (!buf)
                 return nullptr;
 
             ToUpperCaseImpl(buf.get(), chars, i, length);
-            newChars.construct<Latin1CharPtr>(buf);
+            newChars.construct<Latin1CharPtr>(Move(buf));
         } else {
             TwoByteCharPtr buf = cx->make_pod_array<char16_t>(length + 1);
             if (!buf)
                 return nullptr;
 
             ToUpperCaseImpl(buf.get(), chars, i, length);
-            newChars.construct<TwoByteCharPtr>(buf);
+            newChars.construct<TwoByteCharPtr>(Move(buf));
         }
     }
 
     JSString *res;
     if (newChars.constructed<Latin1CharPtr>()) {
         res = NewStringDontDeflate<CanGC>(cx, newChars.ref<Latin1CharPtr>().get(), length);
         if (!res)
             return nullptr;
--- a/mfbt/MaybeOneOf.h
+++ b/mfbt/MaybeOneOf.h
@@ -51,46 +51,22 @@ public:
   MaybeOneOf() : state(None) {}
   ~MaybeOneOf() { destroyIfConstructed(); }
 
   bool empty() const { return state == None; }
 
   template <class T>
   bool constructed() const { return state == Type2State<T>::result; }
 
-  template <class T>
-  void construct()
-  {
-    MOZ_ASSERT(state == None);
-    state = Type2State<T>::result;
-    ::new (storage.addr()) T();
-  }
-
-  template <class T, class U>
-  void construct(U&& aU)
+  template <class T, class... Args>
+  void construct(Args&&... aArgs)
   {
     MOZ_ASSERT(state == None);
     state = Type2State<T>::result;
-    ::new (storage.addr()) T(Move(aU));
-  }
-
-  template <class T, class U1>
-  void construct(const U1& aU1)
-  {
-    MOZ_ASSERT(state == None);
-    state = Type2State<T>::result;
-    ::new (storage.addr()) T(aU1);
-  }
-
-  template <class T, class U1, class U2>
-  void construct(const U1& aU1, const U2& aU2)
-  {
-    MOZ_ASSERT(state == None);
-    state = Type2State<T>::result;
-    ::new (storage.addr()) T(aU1, aU2);
+    ::new (storage.addr()) T(Forward<Args>(aArgs)...);
   }
 
   template <class T>
   T& ref()
   {
     return as<T>();
   }