aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-24 12:29:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-24 12:29:57 +0000
commitb2fc0a4a5c22de1f7928dcd0d4e581e469a2a2e1 (patch)
tree59e1723cc75aef19f197f63dc9b7508025aaab90
parentc33e46e1e0801ea3625bf84e56410f0f273306d7 (diff)
downloadruby-b2fc0a4a5c22de1f7928dcd0d4e581e469a2a2e1.tar.gz
st.c: fix arguments order to compare
* st.c (EQUAL, st_delete_safe): fix arguments order to compare function, searching key is the first and stored key is the second always. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--st.c10
2 files changed, 11 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 010902f131..474e191fa9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jul 24 21:29:54 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * st.c (EQUAL, st_delete_safe): fix arguments order to compare
+ function, searching key is the first and stored key is the
+ second always.
+
Fri Jul 24 21:27:29 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (fstr_update_callback): fstring must not be a shared
diff --git a/st.c b/st.c
index e675ee74cb..0125132bb1 100644
--- a/st.c
+++ b/st.c
@@ -86,7 +86,7 @@ static void rehash(st_table *);
#define free(x) xfree(x)
#endif
-#define EQUAL(table,x,y) ((x)==(y) || (*(table)->type->compare)((x),(y)) == 0)
+#define EQUAL(table,x,ent) ((x)==(ent)->key || (*(table)->type->compare)((x),(ent)->key) == 0)
#define do_hash(key,table) (st_index_t)(*(table)->type->hash)((key))
#define hash_pos(h,n) ((h) & (n - 1))
@@ -319,7 +319,7 @@ st_memsize(const st_table *table)
}
#define PTR_NOT_EQUAL(table, ptr, hash_val, key) \
-((ptr) != 0 && ((ptr)->hash != (hash_val) || !EQUAL((table), (key), (ptr)->key)))
+((ptr) != 0 && ((ptr)->hash != (hash_val) || !EQUAL((table), (key), (ptr))))
#ifdef HASH_LOG
static void
@@ -365,7 +365,7 @@ static inline st_index_t
find_packed_index_from(st_table *table, st_index_t hash_val, st_data_t key, st_index_t i)
{
while (i < table->real_entries &&
- (PHASH(table, i) != hash_val || !EQUAL(table, key, PKEY(table, i)))) {
+ (PHASH(table, i) != hash_val || !EQUAL(table, key, &PACKED_ENT(table, i)))) {
i++;
}
return i;
@@ -685,7 +685,7 @@ st_delete(register st_table *table, register st_data_t *key, st_data_t *value)
prev = &table->bins[hash_pos(hash_val, table->num_bins)];
for (;(ptr = *prev) != 0; prev = &ptr->next) {
- if (EQUAL(table, *key, ptr->key)) {
+ if (EQUAL(table, *key, ptr)) {
*prev = ptr->next;
remove_entry(table, ptr);
if (value != 0) *value = ptr->record;
@@ -722,7 +722,7 @@ st_delete_safe(register st_table *table, register st_data_t *key, st_data_t *val
ptr = table->bins[hash_pos(hash_val, table->num_bins)];
for (; ptr != 0; ptr = ptr->next) {
- if ((ptr->key != never) && EQUAL(table, ptr->key, *key)) {
+ if ((ptr->key != never) && EQUAL(table, *key, ptr)) {
remove_entry(table, ptr);
*key = ptr->key;
if (value != 0) *value = ptr->record;