third_party/cairo/src/cairo-hash.c
static cairo_status_t
_cairo_hash_table_manage (cairo_hash_table_t *hash_table)
{
    cairo_hash_table_t tmp;
    unsigned long new_size, i;

    /* Keep between 12.5% and 50% entries in the hash table alive and
     * at least 25% free. */
    unsigned long live_high = *hash_table->table_size >> 1;
    unsigned long live_low = live_high >> 2;
    unsigned long free_low = live_high >> 1;

    tmp = *hash_table;

    if (hash_table->live_entries > live_high)
    {
	tmp.table_size = hash_table->table_size + 1;
	/* This code is being abused if we can't make a table big enough. */
	assert (tmp.table_size - hash_table_sizes <
		ARRAY_LENGTH (hash_table_sizes));
    }
    else if (hash_table->live_entries < live_low)
    {
	/* Can't shrink if we're at the smallest size */
	if (hash_table->table_size == &hash_table_sizes[0])
	    tmp.table_size = hash_table->table_size;
	else
	    tmp.table_size = hash_table->table_size - 1;
    }

    if (tmp.table_size == hash_table->table_size &&
	hash_table->free_entries > free_low)
    {
	/* The number of live entries is within the desired bounds
	 * (we're not going to resize the table) and we have enough
	 * free entries. Do nothing. */
	return CAIRO_STATUS_SUCCESS;
    }

    new_size = *tmp.table_size;
    tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*));
    if (unlikely (tmp.entries == NULL))
	return _cairo_error (CAIRO_STATUS_NO_MEMORY);

    for (i = 0; i < *hash_table->table_size; ++i) {
	if (ENTRY_IS_LIVE (hash_table->entries[i])) {
	    *_cairo_hash_table_lookup_unique_key (&tmp, hash_table->entries[i])
		= hash_table->entries[i];
	}
    }

    free (hash_table->entries);
    hash_table->entries = tmp.entries;
    hash_table->table_size = tmp.table_size;
    hash_table->free_entries = new_size - hash_table->live_entries;

    return CAIRO_STATUS_SUCCESS;
}
/**
 * _cairo_hash_table_manage:
 * @hash_table: a hash table
 *
 * Resize the hash table if the number of entries has gotten much
 * bigger or smaller than the ideal number of entries for the current
 * size and guarantee some free entries to be used as lookup
 * termination points.
 *
 * Return value: %CAIRO_STATUS_SUCCESS if successful or
 * %CAIRO_STATUS_NO_MEMORY if out of memory.
 **/
@hash_table: a hash table

Resize the hash table if the number of entries has gotten much
bigger or smaller than the ideal number of entries for the current
size and guarantee some free entries to be used as lookup
termination points.

Return value: %CAIRO_STATUS_SUCCESS if successful or
%CAIRO_STATUS_NO_MEMORY if out of memory.
@hash_table : a hash table Resize the hash table if the number of entries has gotten much bigger or smaller than the ideal number of entries for the current size and guarantee some free entries to be used as lookup termination points . Return value : %CAIRO_STATUS_SUCCESS if successful or %CAIRO_STATUS_NO_MEMORY if out of memory .
static cairo_status_t
_cairo_hash_table_manage (cairo_hash_table_t *hash_table)
{
    cairo_hash_table_t tmp;
    unsigned long new_size, i;
    unsigned long live_high = *hash_table->table_size >> 1;
    unsigned long live_low = live_high >> 2;
    unsigned long free_low = live_high >> 1;
    tmp = *hash_table;
    if (hash_table->live_entries > live_high)
    {
	tmp.table_size = hash_table->table_size + 1;
	assert (tmp.table_size - hash_table_sizes <
		ARRAY_LENGTH (hash_table_sizes));
    }
    else if (hash_table->live_entries < live_low)
    {
	if (hash_table->table_size == &hash_table_sizes[0])
	    tmp.table_size = hash_table->table_size;
	else
	    tmp.table_size = hash_table->table_size - 1;
    }
    if (tmp.table_size == hash_table->table_size &&
	hash_table->free_entries > free_low)
    {
	return CAIRO_STATUS_SUCCESS;
    }
    new_size = *tmp.table_size;
    tmp.entries = calloc (new_size, sizeof (cairo_hash_entry_t*));
    if (unlikely (tmp.entries == NULL))
	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
    for (i = 0; i < *hash_table->table_size; ++i) {
	if (ENTRY_IS_LIVE (hash_table->entries[i])) {
	    *_cairo_hash_table_lookup_unique_key (&tmp, hash_table->entries[i])
		= hash_table->entries[i];
	}
    }
    free (hash_table->entries);
    hash_table->entries = tmp.entries;
    hash_table->table_size = tmp.table_size;
    hash_table->free_entries = new_size - hash_table->live_entries;
    return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t _cairo_hash_table_manage ( cairo_hash_table_t * hash_table ) { cairo_hash_table_t tmp ; unsigned long new_size , i ; unsigned long live_high = * hash_table -> table_size >> 1 ; unsigned long live_low = live_high >> 2 ; unsigned long free_low = live_high >> 1 ; tmp = * hash_table ; if ( hash_table -> live_entries > live_high ) { tmp . table_size = hash_table -> table_size + 1 ; assert ( tmp . table_size - hash_table_sizes < ARRAY_LENGTH ( hash_table_sizes ) ) ; } else if ( hash_table -> live_entries < live_low ) { if ( hash_table -> table_size == & hash_table_sizes [ 0 ] ) tmp . table_size = hash_table -> table_size ; else tmp . table_size = hash_table -> table_size - 1 ; } if ( tmp . table_size == hash_table -> table_size && hash_table -> free_entries > free_low ) { return CAIRO_STATUS_SUCCESS ; } new_size = * tmp . table_size ; tmp . entries = calloc ( new_size , sizeof ( cairo_hash_entry_t * ) ) ; if ( unlikely ( tmp . entries == NULL ) ) return _cairo_error ( CAIRO_STATUS_NO_MEMORY ) ; for ( i = 0 ; i < * hash_table -> table_size ; ++ i ) { if ( ENTRY_IS_LIVE ( hash_table -> entries [ i ] ) ) { * _cairo_hash_table_lookup_unique_key ( & tmp , hash_table -> entries [ i ] ) = hash_table -> entries [ i ] ; } } free ( hash_table -> entries ) ; hash_table -> entries = tmp . entries ; hash_table -> table_size = tmp . table_size ; hash_table -> free_entries = new_size - hash_table -> live_entries ; return CAIRO_STATUS_SUCCESS ; }
_cairo_hash_table_manage:
 @hash_table: a hash table
_cairo_hash_table_manage : @hash_table : a hash table
/* Keep between 12.5% and 50% entries in the hash table alive and
     * at least 25% free. */ /* This code is being abused if we can't make a table big enough. */ /* Can't shrink if we're at the smallest size */ /* The number of live entries is within the desired bounds
	 * (we're not going to resize the table) and we have enough
	 * free entries. Do nothing. */