Bug 1441988 - Simplify AutoVector definitions by making this a template r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 01 Mar 2018 14:47:29 +0000
changeset 405875 bda8de97a6a9113bc0df85e460470290543295c9
parent 405874 8d5acf4f29bb3d620680cf0f9b0ff89b405445f2
child 405876 89c8025537a531a933f727d2655d469159cae83c
push id100332
push userjcoppeard@mozilla.com
push dateThu, 01 Mar 2018 14:47:44 +0000
treeherdermozilla-inbound@bda8de97a6a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1441988
milestone60.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 1441988 - Simplify AutoVector definitions by making this a template r=sfink
dom/base/nsJSEnvironment.h
js/public/Class.h
js/public/GCVector.h
js/src/NamespaceImports.h
js/src/jsapi.h
js/src/jspubtd.h
js/xpconnect/wrappers/FilteringWrapper.h
--- a/dom/base/nsJSEnvironment.h
+++ b/dom/base/nsJSEnvironment.h
@@ -18,20 +18,16 @@
 #include "mozilla/TimeStamp.h"
 #include "nsThreadUtils.h"
 #include "xpcpublic.h"
 
 class nsICycleCollectorListener;
 class nsScriptNameSpaceManager;
 class nsIDocShell;
 
-namespace JS {
-class AutoValueVector;
-} // namespace JS
-
 namespace mozilla {
 template <class> class Maybe;
 struct CycleCollectorResults;
 } // namespace mozilla
 
 // The amount of time we wait between a request to GC (due to leaving
 // a page) and doing the actual GC.
 #define NS_GC_DELAY                 4000 // ms
--- a/js/public/Class.h
+++ b/js/public/Class.h
@@ -35,18 +35,16 @@ class Shape;
 // This is equal to JSFunction::class_.  Use it in places where you don't want
 // to #include jsfun.h.
 extern JS_FRIEND_DATA(const js::Class* const) FunctionClassPtr;
 
 } // namespace js
 
 namespace JS {
 
-class AutoIdVector;
-
 /**
  * The answer to a successful query as to whether an object is an Array per
  * ES6's internal |IsArray| operation (as exposed by |Array.isArray|).
  */
 enum class IsArrayAnswer
 {
     Array,
     NotArray,
--- a/js/public/GCVector.h
+++ b/js/public/GCVector.h
@@ -94,24 +94,24 @@ class GCVector
     template<typename U> void
     infallibleAppend(const U* aBegin, const U* aEnd) {
         return vector.infallibleAppend(aBegin, aEnd);
     }
     template<typename U> void infallibleAppend(const U* aBegin, size_t aLength) {
         return vector.infallibleAppend(aBegin, aLength);
     }
 
-    template<typename U, size_t O, class BP>
-    MOZ_MUST_USE bool appendAll(const mozilla::Vector<U, O, BP>& aU) { return vector.appendAll(aU); }
-    template<typename U, size_t O, class BP>
-    MOZ_MUST_USE bool appendAll(const GCVector<U, O, BP>& aU) {
-        return vector.append(aU.begin(), aU.length());
+    template<typename U>
+    MOZ_MUST_USE bool appendAll(const U& aU) {
+        return vector.append(aU.begin(), aU.end());
     }
 
-    MOZ_MUST_USE bool appendN(const T& val, size_t count) { return vector.appendN(val, count); }
+    MOZ_MUST_USE bool appendN(const T& val, size_t count) {
+        return vector.appendN(val, count);
+    }
 
     template<typename U>
     MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd) {
         return vector.append(aBegin, aEnd);
     }
     template<typename U>
     MOZ_MUST_USE bool append(const U* aBegin, size_t aLength) {
         return vector.append(aBegin, aLength);
@@ -214,20 +214,18 @@ class MutableWrappedPtrOperations<JS::GC
     void clear() { vec().clear(); }
     void clearAndFree() { vec().clearAndFree(); }
     template<typename U>
     MOZ_MUST_USE bool append(U&& aU) { return vec().append(mozilla::Forward<U>(aU)); }
     template<typename... Args>
     MOZ_MUST_USE bool emplaceBack(Args&&... aArgs) {
         return vec().emplaceBack(mozilla::Forward<Args...>(aArgs...));
     }
-    template<typename U, size_t O, class BP>
-    MOZ_MUST_USE bool appendAll(const mozilla::Vector<U, O, BP>& aU) { return vec().appendAll(aU); }
-    template<typename U, size_t O, class BP>
-    MOZ_MUST_USE bool appendAll(const JS::GCVector<U, O, BP>& aU) { return vec().appendAll(aU); }
+    template<typename U>
+    MOZ_MUST_USE bool appendAll(const U& aU) { return vec().appendAll(aU); }
     MOZ_MUST_USE bool appendN(const T& aT, size_t aN) { return vec().appendN(aT, aN); }
     template<typename U>
     MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd) {
         return vec().append(aBegin, aEnd);
     }
     template<typename U>
     MOZ_MUST_USE bool append(const U* aBegin, size_t aLength) {
         return vec().append(aBegin, aLength);
@@ -248,9 +246,22 @@ class MutableWrappedPtrOperations<JS::GC
         return vec().insert(aP, mozilla::Forward<U>(aVal));
     }
     void erase(T* aT) { vec().erase(aT); }
     void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); }
 };
 
 } // namespace js
 
+namespace JS {
+
+// An automatically rooted vector for stack use.
+template <typename T>
+class AutoVector : public Rooted<GCVector<T, 8>> {
+    using Vec = GCVector<T, 8>;
+    using Base = Rooted<Vec>;
+  public:
+    explicit AutoVector(JSContext* cx) : Base(cx, Vec(cx)) {}
+};
+
+} // namespace JS
+
 #endif // js_GCVector_h
--- a/js/src/NamespaceImports.h
+++ b/js/src/NamespaceImports.h
@@ -25,19 +25,19 @@ namespace JS {
 class Latin1Chars;
 class Latin1CharsZ;
 class ConstTwoByteChars;
 class TwoByteChars;
 class TwoByteCharsZ;
 class UTF8Chars;
 class UTF8CharsZ;
 
-class AutoValueVector;
-class AutoIdVector;
-class AutoObjectVector;
+using AutoValueVector = AutoVector<Value>;
+using AutoIdVector = AutoVector<jsid>;
+using AutoObjectVector = AutoVector<JSObject*>;
 
 using ValueVector = JS::GCVector<JS::Value>;
 using IdVector = JS::GCVector<jsid>;
 using ScriptVector = JS::GCVector<JSScript*>;
 
 template<typename K, typename V> class AutoHashMapRooter;
 template<typename T> class AutoHashSetRooter;
 
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -97,39 +97,16 @@ class MOZ_RAII AutoValueArray : public A
     MutableHandleValue operator[](unsigned i) {
         MOZ_ASSERT(i < N);
         return MutableHandleValue::fromMarkedLocation(&elements_[i]);
     }
 
     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
 };
 
-class AutoValueVector : public Rooted<GCVector<Value, 8>> {
-    using Vec = GCVector<Value, 8>;
-    using Base = Rooted<Vec>;
-  public:
-    explicit AutoValueVector(JSContext* cx) : Base(cx, Vec(cx)) {}
-};
-
-class AutoIdVector : public Rooted<GCVector<jsid, 8>> {
-    using Vec = GCVector<jsid, 8>;
-    using Base = Rooted<Vec>;
-  public:
-    explicit AutoIdVector(JSContext* cx) : Base(cx, Vec(cx)) {}
-
-    bool appendAll(const AutoIdVector& other) { return this->Base::appendAll(other.get()); }
-};
-
-class AutoObjectVector : public Rooted<GCVector<JSObject*, 8>> {
-    using Vec = GCVector<JSObject*, 8>;
-    using Base = Rooted<Vec>;
-  public:
-    explicit AutoObjectVector(JSContext* cx) : Base(cx, Vec(cx)) {}
-};
-
 using ValueVector = JS::GCVector<JS::Value>;
 using IdVector = JS::GCVector<jsid>;
 using ScriptVector = JS::GCVector<JSScript*>;
 using StringVector = JS::GCVector<JSString*>;
 
 template<class Key, class Value>
 class MOZ_RAII AutoHashMapRooter : protected AutoGCRooter
 {
--- a/js/src/jspubtd.h
+++ b/js/src/jspubtd.h
@@ -24,17 +24,21 @@
 #include "js/TypeDecls.h"
 
 #if defined(JS_GC_ZEAL) || defined(DEBUG)
 # define JSGC_HASH_TABLE_CHECKS
 #endif
 
 namespace JS {
 
-class AutoIdVector;
+template <typename T> class AutoVector;
+using AutoIdVector = AutoVector<jsid>;
+using AutoValueVector = AutoVector<Value>;
+using AutoObjectVector = AutoVector<JSObject*>;
+
 class CallArgs;
 
 class JS_FRIEND_API(CompileOptions);
 class JS_FRIEND_API(ReadOnlyCompileOptions);
 class JS_FRIEND_API(OwningCompileOptions);
 class JS_FRIEND_API(TransitiveCompileOptions);
 class JS_PUBLIC_API(CompartmentOptions);
 
--- a/js/xpconnect/wrappers/FilteringWrapper.h
+++ b/js/xpconnect/wrappers/FilteringWrapper.h
@@ -7,20 +7,16 @@
 #ifndef __FilteringWrapper_h__
 #define __FilteringWrapper_h__
 
 #include "XrayWrapper.h"
 #include "mozilla/Attributes.h"
 #include "js/CallNonGenericMethod.h"
 #include "js/Wrapper.h"
 
-namespace JS {
-class AutoIdVector;
-} // namespace JS
-
 namespace xpc {
 
 template <typename Base, typename Policy>
 class FilteringWrapper : public Base {
   public:
     constexpr explicit FilteringWrapper(unsigned flags) : Base(flags) {}
 
     virtual bool enter(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<jsid> id,