Bug 1367904 - Part 15: stylo: Override ArenaRefPtr for ServoStyleContexts; r?bholley
MozReview-Commit-ID: BV4ek093JCR
--- a/layout/base/ArenaRefPtr.h
+++ b/layout/base/ArenaRefPtr.h
@@ -13,16 +13,27 @@
#ifndef mozilla_ArenaRefPtr_h
#define mozilla_ArenaRefPtr_h
class nsPresArena;
namespace mozilla {
+// Most consumers of ArenaRefPtr will unconditionally use the arena
+// However, nsStyleContext only uses the arena if it is a GeckoStyleContext
+// so we need a mechanism to override this
+template<class U>
+struct ArenaRefPtrTraits
+{
+ static bool UsesArena(U* aPtr) {
+ return true;
+ }
+};
+
/**
* A class for holding strong references to nsPresArena-allocated
* objects.
*
* Since the arena's lifetime is not related to the refcounts
* of the objects allocated within it, it is possible to have a strong
* reference to an arena-allocated object that lives until the
* destruction of the arena. An ArenaRefPtr acts like a weak reference
@@ -138,22 +149,22 @@ private:
template<typename I>
void assignFrom(I& aPtr)
{
if (aPtr == mPtr) {
return;
}
bool sameArena = mPtr && aPtr && mPtr->Arena() == aPtr->Arena();
- if (mPtr && !sameArena) {
+ if (mPtr && !sameArena && ArenaRefPtrTraits<T>::UsesArena(mPtr)) {
MOZ_ASSERT(mPtr->Arena());
mPtr->Arena()->DeregisterArenaRefPtr(this);
}
mPtr = Move(aPtr);
- if (mPtr && !sameArena) {
+ if (mPtr && !sameArena && ArenaRefPtrTraits<T>::UsesArena(aPtr)) {
MOZ_ASSERT(mPtr->Arena());
mPtr->Arena()->RegisterArenaRefPtr(this);
}
}
RefPtr<T> mPtr;
};
--- a/layout/base/ArenaRefPtrInlines.h
+++ b/layout/base/ArenaRefPtrInlines.h
@@ -9,16 +9,17 @@
the inclusion of headers for all types that ArenaRefPtr can handle */
#ifndef mozilla_ArenaRefPtrInlines_h
#define mozilla_ArenaRefPtrInlines_h
#include "mozilla/ArenaObjectID.h"
#include "mozilla/Assertions.h"
#include "nsStyleStruct.h"
+#include "nsStyleContext.h"
namespace mozilla {
template<typename T>
void
ArenaRefPtr<T>::AssertValidType()
{
#ifdef DEBUG
@@ -29,19 +30,29 @@ ArenaRefPtr<T>::AssertValidType()
#undef PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT
false;
MOZ_ASSERT(ok, "ArenaRefPtr<T> template parameter T must be declared in "
"nsPresArenaObjectList with "
"PRES_ARENA_OBJECT_WITH_ARENAREFPTR_SUPPORT");
#endif
}
+template<>
+struct ArenaRefPtrTraits<nsStyleContext>
+{
+ static bool UsesArena(nsStyleContext* aPtr) {
+ MOZ_ASSERT(aPtr);
+ return aPtr->IsGecko();
+ }
+};
+
} // namespace mozilla
template<typename T>
void
nsPresArena::RegisterArenaRefPtr(mozilla::ArenaRefPtr<T>* aPtr)
{
MOZ_ASSERT(!mArenaRefPtrs.Contains(aPtr));
mArenaRefPtrs.Put(aPtr, T::ArenaObjectID());
}
+
#endif