Bug 1308317 - Part 1: Remove debug code. r=froydnj

MozReview-Commit-ID: 7TQG7flcJkj
This commit is contained in:
Eric Rahm 2016-10-13 22:04:33 -07:00
Родитель b8cfe3a083
Коммит f4bf8c3f70
2 изменённых файлов: 2 добавлений и 124 удалений

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

@ -13,73 +13,6 @@
#include "nsIObjectInputStream.h" #include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.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 nsresult
nsQueryElementAt::operator()(const nsIID& aIID, void** aResult) const nsQueryElementAt::operator()(const nsIID& aIID, void** aResult) const
{ {
@ -99,12 +32,6 @@ nsSupportsArray::nsSupportsArray()
mArray = mAutoArray; mArray = mAutoArray;
mArraySize = kAutoArraySize; mArraySize = kAutoArraySize;
mCount = 0; mCount = 0;
#if DEBUG_SUPPORTSARRAY
mMaxCount = 0;
mMaxSize = 0;
ADD_TO_STATS(NumberOfSize, kAutoArraySize * sizeof(mArray[0]));
MaxElements[0]++;
#endif
} }
nsSupportsArray::~nsSupportsArray() nsSupportsArray::~nsSupportsArray()
@ -155,19 +82,6 @@ nsSupportsArray::GrowArrayBy(uint32_t aGrowBy)
mArray = new nsISupports*[newCount.value()]; mArray = new nsISupports*[newCount.value()];
mArraySize = 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 (oldArray) { // need to move old data
if (0 < mCount) { if (0 < mCount) {
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*)); ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
@ -389,14 +303,6 @@ nsSupportsArray::InsertElementAt(nsISupports* aElement, uint32_t aIndex)
NS_IF_ADDREF(aElement); NS_IF_ADDREF(aElement);
mCount++; 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 true;
} }
return false; return false;
@ -500,9 +406,6 @@ nsSupportsArray::Clear(void)
NS_IMETHODIMP NS_IMETHODIMP
nsSupportsArray::Compact(void) nsSupportsArray::Compact(void)
{ {
#if DEBUG_SUPPORTSARRAY
uint32_t oldArraySize = mArraySize;
#endif
if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) { if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) {
nsISupports** oldArray = mArray; nsISupports** oldArray = mArray;
if (mCount <= kAutoArraySize) { if (mCount <= kAutoArraySize) {
@ -516,15 +419,7 @@ nsSupportsArray::Compact(void)
} }
mArraySize = mCount; 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*)); ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
delete[] oldArray; delete[] oldArray;
} }
@ -534,9 +429,6 @@ nsSupportsArray::Compact(void)
NS_IMETHODIMP_(bool) NS_IMETHODIMP_(bool)
nsSupportsArray::SizeTo(int32_t aSize) nsSupportsArray::SizeTo(int32_t aSize)
{ {
#if DEBUG_SUPPORTSARRAY
uint32_t oldArraySize = mArraySize;
#endif
NS_ASSERTION(aSize >= 0, "negative aSize!"); NS_ASSERTION(aSize >= 0, "negative aSize!");
// XXX for aSize < mCount we could resize to mCount // XXX for aSize < mCount we could resize to mCount
@ -557,15 +449,7 @@ nsSupportsArray::SizeTo(int32_t aSize)
} }
mArraySize = aSize; 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*)); ::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
if (oldArray != mAutoArray) { if (oldArray != mAutoArray) {
delete[] oldArray; delete[] oldArray;

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

@ -7,8 +7,6 @@
#ifndef nsSupportsArray_h__ #ifndef nsSupportsArray_h__
#define nsSupportsArray_h__ #define nsSupportsArray_h__
//#define DEBUG_SUPPORTSARRAY 1
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
@ -131,10 +129,6 @@ protected:
uint32_t mArraySize; uint32_t mArraySize;
uint32_t mCount; uint32_t mCount;
nsISupports* mAutoArray[kAutoArraySize]; nsISupports* mAutoArray[kAutoArraySize];
#if DEBUG_SUPPORTSARRAY
uint32_t mMaxCount;
uint32_t mMaxSize;
#endif
private: private:
// Copy constructors are not allowed // Copy constructors are not allowed