Пример #1
0
static void ResizeMultiPointer (TRI_multi_pointer_t* array) {
  void** oldTable;
  uint64_t oldAlloc;
  uint64_t j;

  oldTable = array->_table;
  oldAlloc = array->_nrAlloc;

  array->_nrAlloc = 2 * array->_nrAlloc + 1;

  array->_table = TRI_Allocate(array->_memoryZone, array->_nrAlloc * sizeof(void*), true);

  if (array->_table == NULL) {
    array->_nrAlloc = oldAlloc;
    array->_table = oldTable;

    return;
  }

  array->_nrUsed = 0;
#ifdef TRI_INTERNAL_STATS
  array->_nrResizes++;
#endif

  // table is already clear by allocate, copy old data
  for (j = 0; j < oldAlloc; j++) {
    if (oldTable[j] != NULL) {
      AddNewElementPointer(array, oldTable[j]);
    }
  }

  TRI_Free(array->_memoryZone, oldTable);
}
Пример #2
0
static void ResizeAssociativePointer (TRI_associative_pointer_t* array) {
  void** oldTable;
  uint64_t oldAlloc;
  uint64_t j;

  oldTable = array->_table;
  oldAlloc = array->_nrAlloc;

  array->_nrAlloc = 2 * array->_nrAlloc + 1;
  array->_nrUsed = 0;
  array->_nrResizes++;

  array->_table = TRI_Allocate(array->_nrAlloc * sizeof(void*));

  for (j = 0; j < array->_nrAlloc; j++) {
    array->_table[j] = NULL;
  }

  for (j = 0; j < oldAlloc; j++) {
    if (oldTable[j] != NULL) {
      AddNewElementPointer(array, oldTable[j]);
    }
  }

  TRI_Free(oldTable);
}
Пример #3
0
static bool ResizeAssociativePointer (TRI_associative_pointer_t* array,
                                      uint32_t targetSize) {
  void** oldTable;
  uint32_t oldAlloc;
  uint32_t j;

  oldTable = array->_table;
  oldAlloc = array->_nrAlloc;

  array->_nrAlloc = targetSize;
#ifdef TRI_INTERNAL_STATS
  array->_nrResizes++;
#endif

  array->_table = static_cast<void**>(TRI_Allocate(array->_memoryZone, (size_t) (array->_nrAlloc * sizeof(void*)), true));

  if (array->_table == NULL) {
    array->_nrAlloc = oldAlloc;
    array->_table = oldTable;

    return false;
  }

  array->_nrUsed = 0;

  // table is already cleared by allocate, copy old data
  for (j = 0; j < oldAlloc; j++) {
    if (oldTable[j] != NULL) {
      AddNewElementPointer(array, oldTable[j]);
    }
  }

  TRI_Free(array->_memoryZone, oldTable);

  return true;
}