skip to calculate hash value on empty Hash ar_table lookup.

* hash.c (ar_lookup): don't calculate hash_value if ar_table is empty.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2019-01-04 07:49:00 +00:00
parent 784df9e6fd
commit 87e628d66b

5
hash.c
View File

@ -928,6 +928,10 @@ ar_insert(VALUE hash, st_data_t key, st_data_t value)
static int static int
ar_lookup(VALUE hash, st_data_t key, st_data_t *value) ar_lookup(VALUE hash, st_data_t key, st_data_t *value)
{ {
if (RHASH_AR_TABLE_SIZE(hash) == 0) {
return 0;
}
else {
st_hash_t hash_value = do_hash(key); st_hash_t hash_value = do_hash(key);
unsigned bin = find_entry(hash, hash_value, key); unsigned bin = find_entry(hash, hash_value, key);
@ -941,6 +945,7 @@ ar_lookup(VALUE hash, st_data_t key, st_data_t *value)
} }
return 1; return 1;
} }
}
} }
static int static int