Bug 891177 - Move js::Swap to mozilla::Swap. r=terrence
authorJeff Walden <jwalden@mit.edu>
Wed, 03 Jul 2013 15:57:33 -0700
changeset 138052 5f48a72285df2862abf39b5d744977887c62960e
parent 138051 c77abc3f3890385967793d19073503c8a183e3f4
child 138053 e53b78dd56590b922037b6fee205b9bf3968b02e
push id24941
push useremorley@mozilla.com
push dateThu, 11 Jul 2013 09:11:18 +0000
treeherdermozilla-central@c89e5b9fe935 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersterrence
bugs891177
milestone25.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 891177 - Move js::Swap to mozilla::Swap. r=terrence
js/public/HashTable.h
js/public/Utility.h
js/public/Vector.h
js/src/jsgc.cpp
mfbt/Move.h
--- a/js/public/HashTable.h
+++ b/js/public/HashTable.h
@@ -643,18 +643,18 @@ class HashTableEntry
     }
 
     void destroy() {
         JS_ASSERT(isLive());
         mem.addr()->~T();
     }
 
     void swap(HashTableEntry *other) {
-        Swap(keyHash, other->keyHash);
-        Swap(mem, other->mem);
+        mozilla::Swap(keyHash, other->keyHash);
+        mozilla::Swap(mem, other->mem);
     }
 
     T &get() { JS_ASSERT(isLive()); return *mem.addr(); }
 
     bool isFree() const    { return keyHash == sFreeKey; }
     void clearLive()       { JS_ASSERT(isLive()); keyHash = sFreeKey; mem.addr()->~T(); }
     void clear()           { if (isLive()) mem.addr()->~T(); keyHash = sFreeKey; }
     bool isRemoved() const { return keyHash == sRemovedKey; }
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -559,25 +559,16 @@ struct ScopedReleasePtrTraits : public S
     static void release(T *ptr) { if (ptr) ptr->release(); }
 };
 SCOPED_TEMPLATE(ScopedReleasePtr, ScopedReleasePtrTraits)
 
 } /* namespace js */
 
 namespace js {
 
-template <class T>
-JS_ALWAYS_INLINE static void
-Swap(T &t, T &u)
-{
-    T tmp(mozilla::Move(t));
-    t = mozilla::Move(u);
-    u = mozilla::Move(tmp);
-}
-
 /*
  * Round x up to the nearest power of 2.  This function assumes that the most
  * significant bit of x is not set, which would lead to overflow.
  */
 JS_ALWAYS_INLINE size_t
 RoundUpPow2(size_t x)
 {
     return size_t(1) << JS_CEILING_LOG2W(x);
--- a/js/public/Vector.h
+++ b/js/public/Vector.h
@@ -1091,25 +1091,25 @@ Vector<T,N,AP>::swap(Vector &other)
     // This only works when inline storage is always empty.
     if (!usingInlineStorage() && other.usingInlineStorage()) {
         other.mBegin = mBegin;
         mBegin = inlineStorage();
     } else if (usingInlineStorage() && !other.usingInlineStorage()) {
         mBegin = other.mBegin;
         other.mBegin = other.inlineStorage();
     } else if (!usingInlineStorage() && !other.usingInlineStorage()) {
-        Swap(mBegin, other.mBegin);
+        mozilla::Swap(mBegin, other.mBegin);
     } else {
         // This case is a no-op, since we'd set both to use their inline storage.
     }
 
-    Swap(mLength, other.mLength);
-    Swap(mCapacity, other.mCapacity);
+    mozilla::Swap(mLength, other.mLength);
+    mozilla::Swap(mCapacity, other.mCapacity);
 #ifdef DEBUG
-    Swap(mReserved, other.mReserved);
+    mozilla::Swap(mReserved, other.mReserved);
 #endif
 }
 
 }  /* namespace js */
 
 #ifdef _MSC_VER
 #pragma warning(pop)
 #endif
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -3,22 +3,25 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* JS Mark-and-Sweep Garbage Collector. */
 
 #include "jsgc.h"
 
-#include "prmjtime.h"
-
 #include "mozilla/DebugOnly.h"
 #include "mozilla/MemoryReporting.h"
+#include "mozilla/Move.h"
 #include "mozilla/Util.h"
 
+#include "prmjtime.h"
+
+using mozilla::Swap;
+
 /*
  * This code implements a mark-and-sweep garbage collector. The mark phase is
  * incremental. Most sweeping is done on a background thread. A GC is divided
  * into slices as follows:
  *
  * Slice 1: Roots pushed onto the mark stack. The mark stack is processed by
  * popping an element, marking it, and pushing its children.
  *   ... JS code runs ...
@@ -3075,17 +3078,17 @@ js::gc::MarkingValidator::nonIncremental
         }
     }
 
     /* Take a copy of the non-incremental mark state and restore the original. */
     for (GCChunkSet::Range r(runtime->gcChunkSet.all()); !r.empty(); r.popFront()) {
         Chunk *chunk = r.front();
         ChunkBitmap *bitmap = &chunk->bitmap;
         ChunkBitmap *entry = map.lookup(chunk)->value;
-        js::Swap(*entry, *bitmap);
+        Swap(*entry, *bitmap);
     }
 
     /* Restore the weak map and array buffer lists. */
     for (GCCompartmentsIter c(runtime); !c.done(); c.next()) {
         WeakMapBase::resetCompartmentWeakMapList(c);
         ArrayBufferObject::resetArrayBufferList(c);
     }
     WeakMapBase::restoreCompartmentWeakMapLists(weakmaps);
--- a/mfbt/Move.h
+++ b/mfbt/Move.h
@@ -131,11 +131,21 @@ Move(T& t)
 
 template<typename T>
 inline MoveRef<T>
 Move(const T& t)
 {
   return MoveRef<T>(const_cast<T&>(t));
 }
 
+/** Swap |t| and |u| using move-construction if possible. */
+template<typename T>
+inline void
+Swap(T& t, T& u)
+{
+  T tmp(Move(t));
+  t = Move(u);
+  u = Move(tmp);
+}
+
 } // namespace mozilla
 
 #endif // mozilla_Move_h_