Skip to content

Commit 712ba76

Browse files
committed
Make minor performance improvements to st_lookup
1 parent cae657c commit 712ba76

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

st.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -871,19 +871,17 @@ secondary_hash(st_index_t ind, st_table *tab, st_index_t *perterb)
871871
static inline st_index_t
872872
find_entry(st_table *tab, st_hash_t hash_value, st_data_t key)
873873
{
874-
int eq_p, rebuilt_p;
875-
st_index_t i, bound;
876-
st_table_entry *entries;
874+
unsigned short int eq_p, rebuilt_p;
877875

878-
bound = tab->entries_bound;
879-
entries = tab->entries;
880-
for (i = tab->entries_start; i < bound; i++) {
881-
DO_PTR_EQUAL_CHECK(tab, &entries[i], hash_value, key, eq_p, rebuilt_p);
882-
if (EXPECT(rebuilt_p, 0))
883-
return REBUILT_TABLE_ENTRY_IND;
884-
if (eq_p)
885-
return i;
876+
for (st_index_t i = tab->entries_start; i < tab->entries_bound; i++) {
877+
DO_PTR_EQUAL_CHECK(tab, &tab->entries[i], hash_value, key, eq_p, rebuilt_p);
878+
879+
if (EXPECT(rebuilt_p, 0))
880+
return REBUILT_TABLE_ENTRY_IND;
881+
if (eq_p)
882+
return i;
886883
}
884+
887885
return UNDEFINED_ENTRY_IND;
888886
}
889887

@@ -898,29 +896,25 @@ find_entry(st_table *tab, st_hash_t hash_value, st_data_t key)
898896
static st_index_t
899897
find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key)
900898
{
901-
int eq_p, rebuilt_p;
902-
st_index_t ind;
903-
#ifdef QUADRATIC_PROBE
904-
st_index_t d;
905-
#else
906-
st_index_t peterb;
907-
#endif
908-
st_index_t bin;
909-
st_table_entry *entries = tab->entries;
910-
911899
st_assert(tab != NULL);
912900
st_assert(tab->bins != NULL);
913-
ind = hash_bin(hash_value, tab);
901+
902+
unsigned short int eq_p, rebuilt_p;
903+
st_index_t ind = hash_bin(hash_value, tab);
904+
st_index_t bin;
914905
#ifdef QUADRATIC_PROBE
915-
d = 1;
906+
st_index_t d = 1;
916907
#else
917-
peterb = hash_value;
908+
st_index_t peterb = hash_value;
918909
#endif
919910
FOUND_BIN;
911+
920912
for (;;) {
921913
bin = get_bin(tab->bins, get_size_ind(tab), ind);
914+
922915
if (! EMPTY_OR_DELETED_BIN_P(bin)) {
923-
DO_PTR_EQUAL_CHECK(tab, &entries[bin - ENTRY_BASE], hash_value, key, eq_p, rebuilt_p);
916+
DO_PTR_EQUAL_CHECK(tab, &tab->entries[bin - ENTRY_BASE], hash_value, key, eq_p, rebuilt_p);
917+
924918
if (EXPECT(rebuilt_p, 0))
925919
return REBUILT_TABLE_ENTRY_IND;
926920
if (eq_p)

0 commit comments

Comments
 (0)