зеркало из https://github.com/github/ruby.git
Move clean-up after table rebuilding
Suppress a false positive alert by CodeQL.
This commit is contained in:
Родитель
76f0eec20f
Коммит
0923a98868
20
st.c
20
st.c
|
@ -718,7 +718,9 @@ count_collision(const struct st_hash_type *type)
|
|||
#error "REBUILD_THRESHOLD should be >= 2"
|
||||
#endif
|
||||
|
||||
static void rebuild_table_with(st_table *new_tab, st_table *tab);
|
||||
static void rebuild_table_with(st_table *const new_tab, st_table *const tab);
|
||||
static void rebuild_move_table(st_table *const new_tab, st_table *const tab);
|
||||
static void rebuild_cleanup(st_table *const tab);
|
||||
|
||||
/* Rebuild table TAB. Rebuilding removes all deleted bins and entries
|
||||
and can change size of the table entries and bins arrays.
|
||||
|
@ -744,11 +746,13 @@ rebuild_table(st_table *tab)
|
|||
new_tab = st_init_table_with_size(tab->type,
|
||||
2 * tab->num_entries - 1);
|
||||
rebuild_table_with(new_tab, tab);
|
||||
rebuild_move_table(new_tab, tab);
|
||||
}
|
||||
rebuild_cleanup(tab);
|
||||
}
|
||||
|
||||
static void
|
||||
rebuild_table_with(st_table *new_tab, st_table *tab)
|
||||
rebuild_table_with(st_table *const new_tab, st_table *const tab)
|
||||
{
|
||||
st_index_t i, ni;
|
||||
unsigned int size_ind;
|
||||
|
@ -780,7 +784,11 @@ rebuild_table_with(st_table *new_tab, st_table *tab)
|
|||
new_tab->num_entries++;
|
||||
ni++;
|
||||
}
|
||||
if (new_tab != tab) {
|
||||
}
|
||||
|
||||
static void
|
||||
rebuild_move_table(st_table *const new_tab, st_table *const tab)
|
||||
{
|
||||
tab->entry_power = new_tab->entry_power;
|
||||
tab->bin_power = new_tab->bin_power;
|
||||
tab->size_ind = new_tab->size_ind;
|
||||
|
@ -790,6 +798,10 @@ rebuild_table_with(st_table *new_tab, st_table *tab)
|
|||
tab->entries = new_tab->entries;
|
||||
free(new_tab);
|
||||
}
|
||||
|
||||
static void
|
||||
rebuild_cleanup(st_table *const tab)
|
||||
{
|
||||
tab->entries_start = 0;
|
||||
tab->entries_bound = tab->num_entries;
|
||||
tab->rebuilds_num++;
|
||||
|
@ -2319,6 +2331,8 @@ rb_st_compact_table(st_table *tab)
|
|||
/* Compaction: */
|
||||
st_table *new_tab = st_init_table_with_size(tab->type, 2 * num);
|
||||
rebuild_table_with(new_tab, tab);
|
||||
rebuild_move_table(new_tab, tab);
|
||||
rebuild_cleanup(tab);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче