Skip to content

Commit

Permalink
Bug 1406303 - Only store 2 levels of bit sizes for the radix tree. r=njn
Browse files Browse the repository at this point in the history
All levels except the first are using the same size, and in some cases,
even the first uses the same size. Only storing those two different
sizes allows to fix the class size, while not making the code
significantly more complex.

--HG--
extra : rebase_source : 8028c18de2fa84060c5baff7c95cd0a70e7a3c6b
  • Loading branch information
glandium committed Oct 6, 2017
1 parent 69e4684 commit 8dd4935
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions memory/build/mozjemalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class AddressRadixTree {
malloc_spinlock_t mLock;
void** mRoot;
unsigned mHeight;
unsigned mLevel2Bits[1]; // Dynamically sized.
unsigned mLevel2Bits[2];

public:
static AddressRadixTree* Create(unsigned aBits);
Expand Down Expand Up @@ -1737,13 +1737,12 @@ AddressRadixTree*
AddressRadixTree::Create(unsigned aBits)
{
AddressRadixTree* ret;
unsigned bits_per_level, height, i;
unsigned bits_per_level, height;

bits_per_level = AddressRadixTree::kNodeSize2Pow - SIZEOF_PTR_2POW;
height = (aBits + bits_per_level - 1) / bits_per_level;

ret = (AddressRadixTree*)base_calloc(1, sizeof(AddressRadixTree) +
(sizeof(unsigned) * (height - 1)));
ret = (AddressRadixTree*)base_calloc(1, sizeof(AddressRadixTree));
if (!ret) {
return nullptr;
}
Expand All @@ -1755,9 +1754,7 @@ AddressRadixTree::Create(unsigned aBits)
} else {
ret->mLevel2Bits[0] = bits_per_level;
}
for (i = 1; i < height; i++) {
ret->mLevel2Bits[i] = bits_per_level;
}
ret->mLevel2Bits[1] = bits_per_level;

ret->mRoot = (void**)base_calloc(1 << ret->mLevel2Bits[0], sizeof(void*));
if (!ret->mRoot) {
Expand All @@ -1780,11 +1777,11 @@ AddressRadixTree::GetSlot(void* aKey, bool aCreate)
for (i = lshift = 0, height = mHeight, node = mRoot;
i < height - 1;
i++, lshift += bits, node = child) {
bits = mLevel2Bits[i];
bits = mLevel2Bits[i ? 1 : 0];
subkey = (key << lshift) >> ((SIZEOF_PTR << 3) - bits);
child = (void**) node[subkey];
if (!child && aCreate) {
child = (void**) base_calloc(1 << mLevel2Bits[i + 1], sizeof(void*));
child = (void**) base_calloc(1 << mLevel2Bits[1], sizeof(void*));
if (child) {
node[subkey] = child;
}
Expand All @@ -1798,7 +1795,7 @@ AddressRadixTree::GetSlot(void* aKey, bool aCreate)
* node is a leaf, so it contains values rather than node
* pointers.
*/
bits = mLevel2Bits[i];
bits = mLevel2Bits[i ? 1 : 0];
subkey = (key << lshift) >> ((SIZEOF_PTR << 3) - bits);
return &node[subkey];
}
Expand Down

0 comments on commit 8dd4935

Please sign in to comment.