Optimize xml_allocator::reserve()

Make sure compact_hash_table::rehash() is not inlined - that way reserve() is
inlined so the fast path has no extra function calls.

Also use subtraction instead of multiplication when checking capacity.
This commit is contained in:
Arseny Kapoulkine 2015-04-21 23:02:44 -07:00
parent 52bcb4ecd6
commit 33b2efe318

View File

@ -338,7 +338,7 @@ PUGI__NS_BEGIN
bool reserve() bool reserve()
{ {
if (_count + 16 >= _capacity * 3 / 4) if (_count + 16 >= _capacity - _capacity / 4)
return rehash(); return rehash();
return true; return true;
@ -356,7 +356,24 @@ PUGI__NS_BEGIN
size_t _count; size_t _count;
bool rehash() bool rehash();
static unsigned int hash(const void* key)
{
unsigned int h = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(key));
// MurmurHash3 32-bit finalizer
h ^= h >> 16;
h *= 0x85ebca6bu;
h ^= h >> 13;
h *= 0xc2b2ae35u;
h ^= h >> 16;
return h;
}
};
PUGI__FN_NO_INLINE bool compact_hash_table::rehash()
{ {
compact_hash_table rt; compact_hash_table rt;
rt._capacity = (_capacity == 0) ? 32 : _capacity * 2; rt._capacity = (_capacity == 0) ? 32 : _capacity * 2;
@ -380,20 +397,6 @@ PUGI__NS_BEGIN
return true; return true;
} }
static unsigned int hash(const void* key)
{
unsigned int h = static_cast<unsigned int>(reinterpret_cast<uintptr_t>(key));
// MurmurHash3 32-bit finalizer
h ^= h >> 16;
h *= 0x85ebca6bu;
h ^= h >> 13;
h *= 0xc2b2ae35u;
h ^= h >> 16;
return h;
}
};
PUGI__NS_END PUGI__NS_END
#endif #endif