mirror of https://gitee.com/bigwinds/arangodb
less re-allocations
This commit is contained in:
parent
0fbb3882e4
commit
904a85a27e
|
@ -527,16 +527,16 @@ TRI_shape_aid_t VocShaper::findOrCreateAttributeByName(char const* name) {
|
|||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_attributeIdsLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_attributeIds, _attributeIds._nrUsed + 1)) {
|
||||
return 0;
|
||||
if (! TRI_ReserveAssociativePointer(&_attributeIds, 1)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_attributeNamesLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_attributeNames, _attributeNames._nrUsed + 1)) {
|
||||
return 0;
|
||||
if (! TRI_ReserveAssociativePointer(&_attributeNames, 1)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,11 +640,19 @@ TRI_shape_t const* VocShaper::findShape(TRI_shape_t* shape, bool create) {
|
|||
THROW_ARANGO_EXCEPTION(TRI_ERROR_DEBUG);
|
||||
}
|
||||
|
||||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_shapeIdsLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_shapeIds, 1)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_shapeDictionaryLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_shapeDictionary, _shapeDictionary._nrUsed + 1)) {
|
||||
return 0;
|
||||
if (! TRI_ReserveAssociativePointer(&_shapeDictionary, 1)) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1224,7 @@ TRI_shape_path_t const* VocShaper::findShapePathByName(char const* name,
|
|||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_attributePathsByNameLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_attributePathsByName, _attributePathsByName._nrUsed + 1)) {
|
||||
if (! TRI_ReserveAssociativePointer(&_attributePathsByName, 1)) {
|
||||
TRI_Free(_memoryZone, result);
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1225,7 +1233,7 @@ TRI_shape_path_t const* VocShaper::findShapePathByName(char const* name,
|
|||
{
|
||||
// make room for one more element
|
||||
WRITE_LOCKER(_attributePathsByPidLock);
|
||||
if (! TRI_ReserveAssociativePointer(&_attributePathsByPid, _attributePathsByPid._nrUsed + 1)) {
|
||||
if (! TRI_ReserveAssociativePointer(&_attributePathsByPid, 1)) {
|
||||
TRI_Free(_memoryZone, result);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -179,16 +179,22 @@ bool TRI_EqualStringKeyAssociativePointer(TRI_associative_pointer_t* array,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_ReserveAssociativePointer(TRI_associative_pointer_t* array,
|
||||
int32_t nrElements) {
|
||||
uint32_t nrElements) {
|
||||
uint32_t targetSize = array->_nrUsed + nrElements;
|
||||
|
||||
if (array->_nrAlloc < 2 * targetSize) {
|
||||
// we must resize
|
||||
return ResizeAssociativePointer(array, (uint32_t)(2 * targetSize) + 1);
|
||||
if (array->_nrAlloc >= 2 * targetSize) {
|
||||
// no need to resize
|
||||
return true;
|
||||
}
|
||||
|
||||
// no seed to resize
|
||||
return true;
|
||||
// we must resize
|
||||
|
||||
// make sure we grow the array by a huge amount so we have only few resizes
|
||||
if (targetSize < (2 * array->_nrAlloc) + 1) {
|
||||
targetSize = (2 * array->_nrAlloc) + 1;
|
||||
}
|
||||
|
||||
return ResizeAssociativePointer(array, targetSize);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -101,7 +101,7 @@ bool TRI_EqualStringKeyAssociativePointer(TRI_associative_pointer_t*,
|
|||
/// @brief reserves space in the array for extra elements
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool TRI_ReserveAssociativePointer(TRI_associative_pointer_t*, int32_t);
|
||||
bool TRI_ReserveAssociativePointer(TRI_associative_pointer_t*, uint32_t);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief lookups an element given a key
|
||||
|
|
Loading…
Reference in New Issue