#pragma mark - 扩容操作 // Grow the given zone's table of weak references if it is full. staticvoidweak_grow_maybe(weak_table_t *weak_table){ size_t old_size = TABLE_SIZE(weak_table); // Grow if at least 3/4 full. if (weak_table->num_entries >= old_size * 3 / 4) { weak_resize(weak_table, old_size ? old_size*2 : 64); } }
#pragma mark - 缩容操作 // Shrink the table if it is mostly empty. staticvoidweak_compact_maybe(weak_table_t *weak_table){ size_t old_size = TABLE_SIZE(weak_table); // Shrink if larger than 1024 buckets and at most 1/16 full. if (old_size >= 1024 && old_size / 16 >= weak_table->num_entries) { weak_resize(weak_table, old_size / 8); // leaves new table no more than 1/2 full } }