Differential D3143 Diff 14286 ps/trunk/libraries/source/spidermonkey/include-win32-debug/js/GCVector.h
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/libraries/source/spidermonkey/include-win32-debug/js/GCVector.h
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||||
* vim: set ts=8 sts=4 et sw=4 tw=99: | * vim: set ts=8 sts=2 et sw=2 tw=80: | ||||
* This Source Code Form is subject to the terms of the Mozilla Public | * 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 | * 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/. */ | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||||
#ifndef js_GCVector_h | #ifndef js_GCVector_h | ||||
#define js_GCVector_h | #define js_GCVector_h | ||||
#include "mozilla/Vector.h" | #include "mozilla/Vector.h" | ||||
Show All 22 Lines | |||||
template <typename T, size_t MinInlineCapacity = 0, | template <typename T, size_t MinInlineCapacity = 0, | ||||
typename AllocPolicy = js::TempAllocPolicy> | typename AllocPolicy = js::TempAllocPolicy> | ||||
class GCVector { | class GCVector { | ||||
mozilla::Vector<T, MinInlineCapacity, AllocPolicy> vector; | mozilla::Vector<T, MinInlineCapacity, AllocPolicy> vector; | ||||
public: | public: | ||||
explicit GCVector(AllocPolicy alloc = AllocPolicy()) : vector(alloc) {} | explicit GCVector(AllocPolicy alloc = AllocPolicy()) : vector(alloc) {} | ||||
GCVector(GCVector&& vec) : vector(mozilla::Move(vec.vector)) {} | GCVector(GCVector&& vec) : vector(std::move(vec.vector)) {} | ||||
GCVector& operator=(GCVector&& vec) { | GCVector& operator=(GCVector&& vec) { | ||||
vector = mozilla::Move(vec.vector); | vector = std::move(vec.vector); | ||||
return *this; | return *this; | ||||
} | } | ||||
size_t length() const { return vector.length(); } | size_t length() const { return vector.length(); } | ||||
bool empty() const { return vector.empty(); } | bool empty() const { return vector.empty(); } | ||||
size_t capacity() const { return vector.capacity(); } | size_t capacity() const { return vector.capacity(); } | ||||
T* begin() { return vector.begin(); } | T* begin() { return vector.begin(); } | ||||
Show All 14 Lines | public: | ||||
MOZ_MUST_USE bool growBy(size_t amount) { return vector.growBy(amount); } | MOZ_MUST_USE bool growBy(size_t amount) { return vector.growBy(amount); } | ||||
MOZ_MUST_USE bool resize(size_t newLen) { return vector.resize(newLen); } | MOZ_MUST_USE bool resize(size_t newLen) { return vector.resize(newLen); } | ||||
void clear() { return vector.clear(); } | void clear() { return vector.clear(); } | ||||
void clearAndFree() { return vector.clearAndFree(); } | void clearAndFree() { return vector.clearAndFree(); } | ||||
template <typename U> | template <typename U> | ||||
bool append(U&& item) { | bool append(U&& item) { | ||||
return vector.append(mozilla::Forward<U>(item)); | return vector.append(std::forward<U>(item)); | ||||
} | } | ||||
template <typename... Args> | template <typename... Args> | ||||
MOZ_MUST_USE bool emplaceBack(Args&&... args) { | MOZ_MUST_USE bool emplaceBack(Args&&... args) { | ||||
return vector.emplaceBack(mozilla::Forward<Args>(args)...); | return vector.emplaceBack(std::forward<Args>(args)...); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
void infallibleAppend(U&& aU) { | void infallibleAppend(U&& aU) { | ||||
return vector.infallibleAppend(mozilla::Forward<U>(aU)); | return vector.infallibleAppend(std::forward<U>(aU)); | ||||
} | } | ||||
void infallibleAppendN(const T& aT, size_t aN) { | void infallibleAppendN(const T& aT, size_t aN) { | ||||
return vector.infallibleAppendN(aT, aN); | return vector.infallibleAppendN(aT, aN); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
void infallibleAppend(const U* aBegin, const U* aEnd) { | void infallibleAppend(const U* aBegin, const U* aEnd) { | ||||
return vector.infallibleAppend(aBegin, aEnd); | return vector.infallibleAppend(aBegin, aEnd); | ||||
} | } | ||||
Show All 29 Lines | public: | ||||
size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { | size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const { | ||||
return vector.sizeOfIncludingThis(mallocSizeOf); | return vector.sizeOfIncludingThis(mallocSizeOf); | ||||
} | } | ||||
static void trace(GCVector* vec, JSTracer* trc) { vec->trace(trc); } | static void trace(GCVector* vec, JSTracer* trc) { vec->trace(trc); } | ||||
void trace(JSTracer* trc) { | void trace(JSTracer* trc) { | ||||
for (auto& elem : vector) GCPolicy<T>::trace(trc, &elem, "vector element"); | for (auto& elem : vector) { | ||||
GCPolicy<T>::trace(trc, &elem, "vector element"); | |||||
} | |||||
} | } | ||||
bool needsSweep() const { return !this->empty(); } | bool needsSweep() const { return !this->empty(); } | ||||
void sweep() { | void sweep() { | ||||
uint32_t src, dst = 0; | uint32_t src, dst = 0; | ||||
for (src = 0; src < length(); src++) { | for (src = 0; src < length(); src++) { | ||||
if (!GCPolicy<T>::needsSweep(&vector[src])) { | if (!GCPolicy<T>::needsSweep(&vector[src])) { | ||||
if (dst != src) vector[dst] = vector[src].unbarrieredGet(); | if (dst != src) { | ||||
vector[dst] = vector[src].unbarrieredGet(); | |||||
} | |||||
dst++; | dst++; | ||||
} | } | ||||
} | } | ||||
if (dst != length()) vector.shrinkTo(dst); | if (dst != length()) { | ||||
vector.shrinkTo(dst); | |||||
} | } | ||||
} | |||||
}; | |||||
// AllocPolicy is optional. It has a default value declared in TypeDecls.h | |||||
template <typename T, typename AllocPolicy> | |||||
class MOZ_STACK_CLASS StackGCVector : public GCVector<T, 8, AllocPolicy> { | |||||
public: | |||||
using Base = GCVector<T, 8, AllocPolicy>; | |||||
private: | |||||
// Inherit constructor from GCVector. | |||||
using Base::Base; | |||||
}; | }; | ||||
} // namespace JS | } // namespace JS | ||||
namespace js { | namespace js { | ||||
template <typename Wrapper, typename T, size_t Capacity, typename AllocPolicy> | template <typename Wrapper, typename T, size_t Capacity, typename AllocPolicy> | ||||
class WrappedPtrOperations<JS::GCVector<T, Capacity, AllocPolicy>, Wrapper> { | class WrappedPtrOperations<JS::GCVector<T, Capacity, AllocPolicy>, Wrapper> { | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
MOZ_MUST_USE bool resizeUninitialized(size_t aNewLength) { | MOZ_MUST_USE bool resizeUninitialized(size_t aNewLength) { | ||||
return vec().resizeUninitialized(aNewLength); | return vec().resizeUninitialized(aNewLength); | ||||
} | } | ||||
void clear() { vec().clear(); } | void clear() { vec().clear(); } | ||||
void clearAndFree() { vec().clearAndFree(); } | void clearAndFree() { vec().clearAndFree(); } | ||||
template <typename U> | template <typename U> | ||||
MOZ_MUST_USE bool append(U&& aU) { | MOZ_MUST_USE bool append(U&& aU) { | ||||
return vec().append(mozilla::Forward<U>(aU)); | return vec().append(std::forward<U>(aU)); | ||||
} | } | ||||
template <typename... Args> | template <typename... Args> | ||||
MOZ_MUST_USE bool emplaceBack(Args&&... aArgs) { | MOZ_MUST_USE bool emplaceBack(Args&&... aArgs) { | ||||
return vec().emplaceBack(mozilla::Forward<Args...>(aArgs...)); | return vec().emplaceBack(std::forward<Args>(aArgs)...); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
MOZ_MUST_USE bool appendAll(const U& aU) { | MOZ_MUST_USE bool appendAll(const U& aU) { | ||||
return vec().appendAll(aU); | return vec().appendAll(aU); | ||||
} | } | ||||
MOZ_MUST_USE bool appendN(const T& aT, size_t aN) { | MOZ_MUST_USE bool appendN(const T& aT, size_t aN) { | ||||
return vec().appendN(aT, aN); | return vec().appendN(aT, aN); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd) { | MOZ_MUST_USE bool append(const U* aBegin, const U* aEnd) { | ||||
return vec().append(aBegin, aEnd); | return vec().append(aBegin, aEnd); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
MOZ_MUST_USE bool append(const U* aBegin, size_t aLength) { | MOZ_MUST_USE bool append(const U* aBegin, size_t aLength) { | ||||
return vec().append(aBegin, aLength); | return vec().append(aBegin, aLength); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
void infallibleAppend(U&& aU) { | void infallibleAppend(U&& aU) { | ||||
vec().infallibleAppend(mozilla::Forward<U>(aU)); | vec().infallibleAppend(std::forward<U>(aU)); | ||||
} | } | ||||
void infallibleAppendN(const T& aT, size_t aN) { | void infallibleAppendN(const T& aT, size_t aN) { | ||||
vec().infallibleAppendN(aT, aN); | vec().infallibleAppendN(aT, aN); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
void infallibleAppend(const U* aBegin, const U* aEnd) { | void infallibleAppend(const U* aBegin, const U* aEnd) { | ||||
vec().infallibleAppend(aBegin, aEnd); | vec().infallibleAppend(aBegin, aEnd); | ||||
} | } | ||||
template <typename U> | template <typename U> | ||||
void infallibleAppend(const U* aBegin, size_t aLength) { | void infallibleAppend(const U* aBegin, size_t aLength) { | ||||
vec().infallibleAppend(aBegin, aLength); | vec().infallibleAppend(aBegin, aLength); | ||||
} | } | ||||
void popBack() { vec().popBack(); } | void popBack() { vec().popBack(); } | ||||
T popCopy() { return vec().popCopy(); } | T popCopy() { return vec().popCopy(); } | ||||
template <typename U> | template <typename U> | ||||
T* insert(T* aP, U&& aVal) { | T* insert(T* aP, U&& aVal) { | ||||
return vec().insert(aP, mozilla::Forward<U>(aVal)); | return vec().insert(aP, std::forward<U>(aVal)); | ||||
} | } | ||||
void erase(T* aT) { vec().erase(aT); } | void erase(T* aT) { vec().erase(aT); } | ||||
void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); } | void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); } | ||||
}; | }; | ||||
template <typename Wrapper, typename T, typename AllocPolicy> | |||||
class WrappedPtrOperations<JS::StackGCVector<T, AllocPolicy>, Wrapper> | |||||
: public WrappedPtrOperations< | |||||
typename JS::StackGCVector<T, AllocPolicy>::Base, Wrapper> {}; | |||||
template <typename Wrapper, typename T, typename AllocPolicy> | |||||
class MutableWrappedPtrOperations<JS::StackGCVector<T, AllocPolicy>, Wrapper> | |||||
: public MutableWrappedPtrOperations< | |||||
typename JS::StackGCVector<T, AllocPolicy>::Base, Wrapper> {}; | |||||
} // namespace js | } // namespace js | ||||
namespace JS { | namespace JS { | ||||
// An automatically rooted vector for stack use. | // An automatically rooted GCVector for stack use. | ||||
template <typename T> | template <typename T> | ||||
class AutoVector : public Rooted<GCVector<T, 8>> { | class RootedVector : public Rooted<StackGCVector<T>> { | ||||
using Vec = GCVector<T, 8>; | using Vec = StackGCVector<T>; | ||||
using Base = Rooted<Vec>; | using Base = Rooted<Vec>; | ||||
public: | public: | ||||
explicit AutoVector(JSContext* cx) : Base(cx, Vec(cx)) {} | explicit RootedVector(JSContext* cx) : Base(cx, Vec(cx)) {} | ||||
}; | |||||
// For use in rust code, an analog to RootedVector that doesn't require | |||||
// instances to be destroyed in LIFO order. | |||||
template <typename T> | |||||
class PersistentRootedVector : public PersistentRooted<StackGCVector<T>> { | |||||
using Vec = StackGCVector<T>; | |||||
using Base = PersistentRooted<Vec>; | |||||
public: | |||||
explicit PersistentRootedVector(JSContext* cx) : Base(cx, Vec(cx)) {} | |||||
}; | }; | ||||
} // namespace JS | } // namespace JS | ||||
#endif // js_GCVector_h | #endif // js_GCVector_h |
Wildfire Games · Phabricator