Bug 1170045 - part 2 - use SegmentedVector in the DeferredFinalize implementation; r=mccr8

This change ought to make the necessary allocations for many deferred
finalizations smaller, at the cost of some extra space usage and
slightly slower walking over the array.
This commit is contained in:
Nathan Froyd 2016-03-04 12:06:06 -05:00
Родитель d75c1bad6a
Коммит f1c0aa7371
1 изменённых файлов: 9 добавлений и 8 удалений

Просмотреть файл

@ -24,6 +24,7 @@
#include "mozilla/dom/NonRefcountedDOMObject.h" #include "mozilla/dom/NonRefcountedDOMObject.h"
#include "mozilla/dom/Nullable.h" #include "mozilla/dom/Nullable.h"
#include "mozilla/dom/RootedDictionary.h" #include "mozilla/dom/RootedDictionary.h"
#include "mozilla/SegmentedVector.h"
#include "mozilla/dom/workers/Workers.h" #include "mozilla/dom/workers/Workers.h"
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/Likely.h" #include "mozilla/Likely.h"
@ -2849,27 +2850,27 @@ struct DeferredFinalizerImpl
typename Conditional<IsRefcounted<T>::value, typename Conditional<IsRefcounted<T>::value,
RefPtr<T>, RefPtr<T>,
nsAutoPtr<T>>::Type>::Type SmartPtr; nsAutoPtr<T>>::Type>::Type SmartPtr;
typedef nsTArray<SmartPtr> SmartPtrArray; typedef SegmentedVector<SmartPtr> SmartPtrArray;
static_assert(IsSame<T, nsISupports>::value || !IsBaseOf<nsISupports, T>::value, static_assert(IsSame<T, nsISupports>::value || !IsBaseOf<nsISupports, T>::value,
"nsISupports classes should all use the nsISupports instantiation"); "nsISupports classes should all use the nsISupports instantiation");
static inline void static inline void
AppendAndTake(nsTArray<nsCOMPtr<nsISupports>>& smartPtrArray, nsISupports* ptr) AppendAndTake(SegmentedVector<nsCOMPtr<nsISupports>>& smartPtrArray, nsISupports* ptr)
{ {
smartPtrArray.AppendElement(dont_AddRef(ptr)); smartPtrArray.InfallibleAppend(dont_AddRef(ptr));
} }
template<class U> template<class U>
static inline void static inline void
AppendAndTake(nsTArray<RefPtr<U>>& smartPtrArray, U* ptr) AppendAndTake(SegmentedVector<RefPtr<U>>& smartPtrArray, U* ptr)
{ {
smartPtrArray.AppendElement(dont_AddRef(ptr)); smartPtrArray.InfallibleAppend(dont_AddRef(ptr));
} }
template<class U> template<class U>
static inline void static inline void
AppendAndTake(nsTArray<nsAutoPtr<U>>& smartPtrArray, U* ptr) AppendAndTake(SegmentedVector<nsAutoPtr<U>>& smartPtrArray, U* ptr)
{ {
smartPtrArray.AppendElement(ptr); smartPtrArray.InfallibleAppend(ptr);
} }
static void* static void*
@ -2892,7 +2893,7 @@ struct DeferredFinalizerImpl
aSlice = oldLen; aSlice = oldLen;
} }
uint32_t newLen = oldLen - aSlice; uint32_t newLen = oldLen - aSlice;
pointers->RemoveElementsAt(newLen, aSlice); pointers->PopLastN(aSlice);
if (newLen == 0) { if (newLen == 0) {
delete pointers; delete pointers;
return true; return true;