зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1622260: Replace POOLED_COLLECTION_PTR_METHODS macro with C++ code. r=mgaudet
`acquireCollection` and `releaseCollection` act like an interface subclasses need to implement for `PooledCollectionPtr`. Differential Revision: https://phabricator.services.mozilla.com/D66762 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
18f27b4376
Коммит
c5271d8115
|
@ -240,49 +240,83 @@ class NameCollectionPool {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define POOLED_COLLECTION_PTR_METHODS(N, T) \
|
template <typename T, template <typename> typename Impl>
|
||||||
NameCollectionPool& pool_; \
|
class PooledCollectionPtr {
|
||||||
T* collection_; \
|
NameCollectionPool& pool_;
|
||||||
\
|
T* collection_ = nullptr;
|
||||||
T& collection() { \
|
|
||||||
MOZ_ASSERT(collection_); \
|
protected:
|
||||||
return *collection_; \
|
~PooledCollectionPtr() { Impl<T>::releaseCollection(pool_, &collection_); }
|
||||||
} \
|
|
||||||
\
|
T& collection() {
|
||||||
const T& collection() const { \
|
MOZ_ASSERT(collection_);
|
||||||
MOZ_ASSERT(collection_); \
|
return *collection_;
|
||||||
return *collection_; \
|
}
|
||||||
} \
|
|
||||||
\
|
const T& collection() const {
|
||||||
public: \
|
MOZ_ASSERT(collection_);
|
||||||
explicit N(NameCollectionPool& pool) : pool_(pool), collection_(nullptr) {} \
|
return *collection_;
|
||||||
\
|
}
|
||||||
~N() { pool_.release##T(&collection_); } \
|
|
||||||
\
|
public:
|
||||||
bool acquire(JSContext* cx) { \
|
explicit PooledCollectionPtr(NameCollectionPool& pool) : pool_(pool) {}
|
||||||
MOZ_ASSERT(!collection_); \
|
|
||||||
collection_ = pool_.acquire##T<T>(cx); \
|
bool acquire(JSContext* cx) {
|
||||||
return !!collection_; \
|
MOZ_ASSERT(!collection_);
|
||||||
} \
|
collection_ = Impl<T>::acquireCollection(cx, pool_);
|
||||||
\
|
return !!collection_;
|
||||||
explicit operator bool() const { return !!collection_; } \
|
}
|
||||||
\
|
|
||||||
T* operator->() { return &collection(); } \
|
explicit operator bool() const { return !!collection_; }
|
||||||
\
|
|
||||||
const T* operator->() const { return &collection(); } \
|
T* operator->() { return &collection(); }
|
||||||
\
|
|
||||||
T& operator*() { return collection(); } \
|
const T* operator->() const { return &collection(); }
|
||||||
\
|
|
||||||
|
T& operator*() { return collection(); }
|
||||||
|
|
||||||
const T& operator*() const { return collection(); }
|
const T& operator*() const { return collection(); }
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Map>
|
template <typename Map>
|
||||||
class PooledMapPtr {
|
class PooledMapPtr : public PooledCollectionPtr<Map, PooledMapPtr> {
|
||||||
POOLED_COLLECTION_PTR_METHODS(PooledMapPtr, Map)
|
friend class PooledCollectionPtr<Map, PooledMapPtr>;
|
||||||
|
|
||||||
|
static Map* acquireCollection(JSContext* cx, NameCollectionPool& pool) {
|
||||||
|
return pool.acquireMap<Map>(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releaseCollection(NameCollectionPool& pool, Map** ptr) {
|
||||||
|
pool.releaseMap(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Base = PooledCollectionPtr<Map, PooledMapPtr>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using Base::Base;
|
||||||
|
|
||||||
|
~PooledMapPtr() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Vector>
|
template <typename Vector>
|
||||||
class PooledVectorPtr {
|
class PooledVectorPtr : public PooledCollectionPtr<Vector, PooledVectorPtr> {
|
||||||
POOLED_COLLECTION_PTR_METHODS(PooledVectorPtr, Vector)
|
friend class PooledCollectionPtr<Vector, PooledVectorPtr>;
|
||||||
|
|
||||||
|
static Vector* acquireCollection(JSContext* cx, NameCollectionPool& pool) {
|
||||||
|
return pool.acquireVector<Vector>(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void releaseCollection(NameCollectionPool& pool, Vector** ptr) {
|
||||||
|
pool.releaseVector(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
using Base = PooledCollectionPtr<Vector, PooledVectorPtr>;
|
||||||
|
using Base::collection;
|
||||||
|
|
||||||
|
public:
|
||||||
|
using Base::Base;
|
||||||
|
|
||||||
|
~PooledVectorPtr() = default;
|
||||||
|
|
||||||
typename Vector::ElementType& operator[](size_t index) {
|
typename Vector::ElementType& operator[](size_t index) {
|
||||||
return collection()[index];
|
return collection()[index];
|
||||||
|
@ -293,8 +327,6 @@ class PooledVectorPtr {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef POOLED_COLLECTION_PTR_METHODS
|
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
} // namespace js
|
} // namespace js
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче