summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-04 07:49:00 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-04 07:49:00 +0000
commit87e628d66b7bf98f276dbd38b810f0197f821081 (patch)
treed1afccc0c05406018af35ef0b110b84e2b7ac47c /hash.c
parent784df9e6fd41a73cbdfc22222c5917991aa0825e (diff)
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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index 3cd4776a17..e45a257fc6 100644
--- a/hash.c
+++ b/hash.c
@@ -928,18 +928,23 @@ ar_insert(VALUE hash, st_data_t key, st_data_t value)
static int
ar_lookup(VALUE hash, st_data_t key, st_data_t *value)
{
- st_hash_t hash_value = do_hash(key);
- unsigned bin = find_entry(hash, hash_value, key);
-
- if (bin == RHASH_AR_TABLE_MAX_BOUND) {
+ if (RHASH_AR_TABLE_SIZE(hash) == 0) {
return 0;
}
else {
- HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
- if (value != NULL) {
- *value = RHASH_AR_TABLE_REF(hash, bin)->record;
+ st_hash_t hash_value = do_hash(key);
+ unsigned bin = find_entry(hash, hash_value, key);
+
+ if (bin == RHASH_AR_TABLE_MAX_BOUND) {
+ return 0;
+ }
+ else {
+ HASH_ASSERT(bin < RHASH_AR_TABLE_MAX_BOUND);
+ if (value != NULL) {
+ *value = RHASH_AR_TABLE_REF(hash, bin)->record;
+ }
+ return 1;
}
- return 1;
}
}