Exemple #1
0
static void maybe_resize_string_buffer(size_t additional_chars, GumboStringBuffer* buffer) {
  size_t new_length = buffer->length + additional_chars;
  size_t new_capacity = buffer->capacity;
  while (new_capacity < new_length) {
    new_capacity *= 2;
  }
  if (new_capacity != buffer->capacity) {
    buffer->capacity = new_capacity;
    buffer->data = gumbo_realloc(buffer->data, buffer->capacity);
  }
}
Exemple #2
0
static void enlarge_vector_if_full(GumboVector* vector) {
  if (vector->length >= vector->capacity) {
    if (vector->capacity) {
      vector->capacity *= 2;
      size_t num_bytes = sizeof(void*) * vector->capacity;
      vector->data = gumbo_realloc(vector->data, num_bytes);
    } else {
      // 0-capacity vector; no previous array to deallocate.
      vector->capacity = 2;
      vector->data = gumbo_alloc(sizeof(void*) * vector->capacity);
    }
  }
}