☠☠ backed out by 6343523ec56d ☠ ☠ | |
author | Eric Rahm <erahm@mozilla.com> |
Thu, 13 Oct 2016 22:04:33 -0700 | |
changeset 317937 | ea82808b9abd16a3170b21b9785d0fbef04a863b |
parent 317936 | 5af415bbb1072acb039b7a76779ac91d98762890 |
child 317938 | 63208c26bfc31dc3d448afc579183cd8d67dcb89 |
push id | 33170 |
push user | cbook@mozilla.com |
push date | Fri, 14 Oct 2016 10:37:07 +0000 |
treeherder | autoland@0d101ebfd95c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | froydnj |
bugs | 1308317 |
milestone | 52.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
|
xpcom/ds/nsSupportsArray.cpp | file | annotate | diff | comparison | revisions | |
xpcom/ds/nsSupportsArray.h | file | annotate | diff | comparison | revisions |
--- a/xpcom/ds/nsSupportsArray.cpp +++ b/xpcom/ds/nsSupportsArray.cpp @@ -8,83 +8,16 @@ #include <string.h> #include "mozilla/CheckedInt.h" #include "mozilla/MathAlgorithms.h" #include "nsSupportsArray.h" #include "nsSupportsArrayEnumerator.h" #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" -#if DEBUG_SUPPORTSARRAY -#define MAXSUPPORTS 20 - -class SupportsStats -{ -public: - SupportsStats(); - ~SupportsStats(); - -}; - -static int sizesUsed; // number of the elements of the arrays used -static int sizesAlloced[MAXSUPPORTS]; // sizes of the allocations. sorted -static int NumberOfSize[MAXSUPPORTS]; // number of this allocation size (1 per array) -static int AllocedOfSize[MAXSUPPORTS]; // number of this allocation size (each size for array used) -static int GrowInPlace[MAXSUPPORTS]; - -// these are per-allocation -static int MaxElements[3000]; - -// very evil -#define ADD_TO_STATS(x,size) do {int i; for (i = 0; i < sizesUsed; i++) \ - { \ - if (sizesAlloced[i] == (int)(size)) \ - { ((x)[i])++; break; } \ - } \ - if (i >= sizesUsed && sizesUsed < MAXSUPPORTS) \ - { sizesAlloced[sizesUsed] = (size); \ - ((x)[sizesUsed++])++; break; \ - } \ - } while (0); - -#define SUB_FROM_STATS(x,size) do {int i; for (i = 0; i < sizesUsed; i++) \ - { \ - if (sizesAlloced[i] == (int)(size)) \ - { ((x)[i])--; break; } \ - } \ - } while (0); - - -SupportsStats::SupportsStats() -{ - sizesUsed = 1; - sizesAlloced[0] = 0; -} - -SupportsStats::~SupportsStats() -{ - int i; - for (i = 0; i < sizesUsed; ++i) { - printf("Size %d:\n", sizesAlloced[i]); - printf("\tNumber of SupportsArrays this size (max): %d\n", NumberOfSize[i]); - printf("\tNumber of allocations this size (total): %d\n", AllocedOfSize[i]); - printf("\tNumber of GrowsInPlace this size (total): %d\n", GrowInPlace[i]); - } - printf("Max Size of SupportsArray:\n"); - for (i = 0; i < (int)(sizeof(MaxElements) / sizeof(MaxElements[0])); ++i) { - if (MaxElements[i]) { - printf("\t%d: %d\n", i, MaxElements[i]); - } - } -} - -// Just so constructor/destructor get called -SupportsStats gSupportsStats; -#endif - nsresult nsQueryElementAt::operator()(const nsIID& aIID, void** aResult) const { nsresult status = mCollection ? mCollection->QueryElementAt(mIndex, aIID, aResult) : NS_ERROR_NULL_POINTER; if (mErrorPtr) { @@ -94,22 +27,16 @@ nsQueryElementAt::operator()(const nsIID return status; } nsSupportsArray::nsSupportsArray() { mArray = mAutoArray; mArraySize = kAutoArraySize; mCount = 0; -#if DEBUG_SUPPORTSARRAY - mMaxCount = 0; - mMaxSize = 0; - ADD_TO_STATS(NumberOfSize, kAutoArraySize * sizeof(mArray[0])); - MaxElements[0]++; -#endif } nsSupportsArray::~nsSupportsArray() { DeleteArray(); } bool @@ -150,29 +77,16 @@ nsSupportsArray::GrowArrayBy(uint32_t aG } // XXX This would be far more efficient in many allocators if we used // XXX PR_Realloc(), etc nsISupports** oldArray = mArray; mArray = new nsISupports*[newCount.value()]; mArraySize = newCount.value(); -#if DEBUG_SUPPORTSARRAY - if (oldArray == mArray) { // can't happen without use of realloc - ADD_TO_STATS(GrowInPlace, mCount); - } - ADD_TO_STATS(AllocedOfSize, mArraySize * sizeof(mArray[0])); - if (mArraySize > mMaxSize) { - ADD_TO_STATS(NumberOfSize, mArraySize * sizeof(mArray[0])); - if (oldArray != &(mAutoArray[0])) { - SUB_FROM_STATS(NumberOfSize, mCount * sizeof(mArray[0])); - } - mMaxSize = mArraySize; - } -#endif if (oldArray) { // need to move old data if (0 < mCount) { ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*)); } if (oldArray != &(mAutoArray[0])) { delete[] oldArray; } } @@ -384,24 +298,16 @@ nsSupportsArray::InsertElementAt(nsISupp ::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*)); } mArray[aIndex] = aElement; NS_IF_ADDREF(aElement); mCount++; -#if DEBUG_SUPPORTSARRAY - if (mCount > mMaxCount && - mCount < (int32_t)(sizeof(MaxElements) / sizeof(MaxElements[0]))) { - MaxElements[mCount]++; - MaxElements[mMaxCount]--; - mMaxCount = mCount; - } -#endif return true; } return false; } NS_IMETHODIMP_(bool) nsSupportsArray::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) { @@ -495,53 +401,39 @@ nsSupportsArray::Clear(void) } while (0 != mCount); } return NS_OK; } NS_IMETHODIMP nsSupportsArray::Compact(void) { -#if DEBUG_SUPPORTSARRAY - uint32_t oldArraySize = mArraySize; -#endif if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) { nsISupports** oldArray = mArray; if (mCount <= kAutoArraySize) { mArray = mAutoArray; mArraySize = kAutoArraySize; } else { mArray = new nsISupports*[mCount]; if (!mArray) { mArray = oldArray; return NS_OK; } mArraySize = mCount; } -#if DEBUG_SUPPORTSARRAY - if (oldArray == mArray && - oldArray != &(mAutoArray[0])) { // can't happen without use of realloc - ADD_TO_STATS(GrowInPlace, oldArraySize); - } - if (oldArray != &(mAutoArray[0])) { - ADD_TO_STATS(AllocedOfSize, mArraySize * sizeof(mArray[0])); - } -#endif + ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*)); delete[] oldArray; } return NS_OK; } NS_IMETHODIMP_(bool) nsSupportsArray::SizeTo(int32_t aSize) { -#if DEBUG_SUPPORTSARRAY - uint32_t oldArraySize = mArraySize; -#endif NS_ASSERTION(aSize >= 0, "negative aSize!"); // XXX for aSize < mCount we could resize to mCount if (mArraySize == (uint32_t)aSize || (uint32_t)aSize < mCount) { return true; // nothing to do } // switch back to autoarray if possible @@ -552,25 +444,17 @@ nsSupportsArray::SizeTo(int32_t aSize) } else { mArray = new nsISupports*[aSize]; if (!mArray) { mArray = oldArray; return false; } mArraySize = aSize; } -#if DEBUG_SUPPORTSARRAY - if (oldArray == mArray && - oldArray != &(mAutoArray[0])) { // can't happen without use of realloc - ADD_TO_STATS(GrowInPlace, oldArraySize); - } - if (oldArray != &(mAutoArray[0])) { - ADD_TO_STATS(AllocedOfSize, mArraySize * sizeof(mArray[0])); - } -#endif + ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*)); if (oldArray != mAutoArray) { delete[] oldArray; } return true; }
--- a/xpcom/ds/nsSupportsArray.h +++ b/xpcom/ds/nsSupportsArray.h @@ -2,18 +2,16 @@ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* 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 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsSupportsArray_h__ #define nsSupportsArray_h__ -//#define DEBUG_SUPPORTSARRAY 1 - #include "nsISupportsArray.h" #include "mozilla/Attributes.h" static const uint32_t kAutoArraySize = 8; class nsSupportsArray final : public nsISupportsArray { ~nsSupportsArray(void); // nonvirtual since we're not subclassed @@ -126,19 +124,15 @@ protected: void DeleteArray(void); bool GrowArrayBy(uint32_t aGrowBy); nsISupports** mArray; uint32_t mArraySize; uint32_t mCount; nsISupports* mAutoArray[kAutoArraySize]; -#if DEBUG_SUPPORTSARRAY - uint32_t mMaxCount; - uint32_t mMaxSize; -#endif private: // Copy constructors are not allowed explicit nsSupportsArray(const nsISupportsArray& aOther); }; #endif // nsSupportsArray_h__