Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
st refactor add_packed_direct a bit
  • Loading branch information
funny-falcon committed Jan 5, 2012
commit 44c7d23544180a8ca8d3efe5f1d6b45a26d9f4c2
21 changes: 8 additions & 13 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,18 @@ unpack_entries(register st_table *table)
*table = tmp_table;
}

static int
static void
add_packed_direct(st_table *table, st_data_t key, st_data_t value)
{
int res = 1;
if (table->num_entries < MAX_PACKED_NUMHASH) {
st_index_t i = table->num_entries++;
PKEY_SET(table, i, key);
PVAL_SET(table, i, value);
}
else {
unpack_entries(table);
res = 0;
add_direct(table, key, value, key, key % table->num_bins);
}
return res;
}


Expand All @@ -498,9 +496,8 @@ st_insert(register st_table *table, register st_data_t key, st_data_t value)
PVAL_SET(table, i, value);
return 1;
}
if (add_packed_direct(table, key, value)) {
return 0;
}
add_packed_direct(table, key, value);
return 0;
}

hash_val = do_hash(key, table);
Expand Down Expand Up @@ -530,9 +527,8 @@ st_insert2(register st_table *table, register st_data_t key, st_data_t value,
PVAL_SET(table, i, value);
return 1;
}
if (add_packed_direct(table, key, value)) {
return 0;
}
add_packed_direct(table, key, value);
return 0;
}

hash_val = do_hash(key, table);
Expand All @@ -556,9 +552,8 @@ st_add_direct(st_table *table, st_data_t key, st_data_t value)
st_index_t hash_val, bin_pos;

if (table->entries_packed) {
if (add_packed_direct(table, key, value)) {
return;
}
add_packed_direct(table, key, value);
return;
}

hash_val = do_hash(key, table);
Expand Down