Skip to content

Commit

Permalink
save table->bins and never change the table during unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jan 2, 2012
1 parent c2c346f commit 61f234c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions st.c
Expand Up @@ -368,15 +368,17 @@ unpack_entries(register st_table *table)
{
st_index_t i;
struct st_table_entry *packed_bins[MAX_PACKED_NUMHASH*2];
int num_entries = table->num_entries;
st_table tmp_table = *table;

memcpy(packed_bins, table->bins, sizeof(struct st_table_entry *) * num_entries*2);
table->entries_packed = 0;
table->num_entries = 0;
memset(table->bins, 0, sizeof(struct st_table_entry *) * table->num_bins);
for (i = 0; i < num_entries; i++) {
st_insert(table, (st_data_t)packed_bins[i*2], (st_data_t)packed_bins[i*2+1]);
memcpy(packed_bins, table->bins, sizeof(struct st_table_entry *) * table->num_entries*2);
table->bins = packed_bins;
tmp_table.entries_packed = 0;
tmp_table.num_entries = 0;
memset(tmp_table.bins, 0, sizeof(struct st_table_entry *) * tmp_table.num_bins);
for (i = 0; i < table->num_entries; i++) {
st_insert(&tmp_table, (st_data_t)packed_bins[i*2], (st_data_t)packed_bins[i*2+1]);
}
*table = tmp_table;
}

int
Expand Down

0 comments on commit 61f234c

Please sign in to comment.