Add SizeOf() which is going to be needed for 'plug replacement' of nsVoidArray's

This commit is contained in:
waterson%netscape.com 2000-06-10 07:31:09 +00:00
Родитель 3e5177c70d
Коммит 2b2025c6f9
2 изменённых файлов: 39 добавлений и 0 удалений

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

@ -536,6 +536,42 @@ nsVoidBTree::EnumerateBackwards(EnumFunc aFunc, void* aData) const
return running;
}
void
nsVoidBTree::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
{
if (! aResult)
return;
*aResult = sizeof(*this);
if (IsSingleElement())
return;
Path path;
path.Push(NS_REINTERPRET_CAST(Node*, mRoot & kRoot_PointerMask), 0);
while (path.Length()) {
Node* current;
PRInt32 index;
path.Pop(&current, &index);
if (current->GetType() == Node::eType_Data) {
*aResult += sizeof(Node) + (sizeof(void*) * (kDataCapacity - 1));
}
else {
*aResult += sizeof(Node) + (sizeof(void*) * (kIndexCapacity - 1));
// If we're in an index node, and there are still kids to
// traverse, well, traverse 'em.
if (index < current->GetCount()) {
path.Push(current, index + 1);
path.Push(NS_STATIC_CAST(Node*, current->GetElementAt(index)), 0);
}
}
}
}
//----------------------------------------------------------------------
nsresult

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

@ -25,6 +25,7 @@
#include "nscore.h"
#include "nsDebug.h"
#include "nsError.h"
class nsISizeOfHandler;
/**
* An nsVoidArray-compatible class that is implemented as a B-tree
@ -73,6 +74,8 @@ public:
PRBool EnumerateForwards(EnumFunc aFunc, void* aData) const;
PRBool EnumerateBackwards(EnumFunc aFunc, void* aData) const;
void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
protected:
// This is as deep as a tree can ever grow, mostly because we use an
// automatic variable to keep track of the path we take through the