ruby-changes:54487
From: ko1 <ko1@a...>
Date: Fri, 4 Jan 2019 16:49:05 +0900 (JST)
Subject: [ruby-changes:54487] ko1:r66702 (trunk): skip to calculate hash value on empty Hash ar_table lookup.
ko1 2019-01-04 16:49:00 +0900 (Fri, 04 Jan 2019) New Revision: 66702 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66702 Log: 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. Modified files: trunk/hash.c Index: hash.c =================================================================== --- hash.c (revision 66701) +++ hash.c (revision 66702) @@ -928,18 +928,23 @@ ar_insert(VALUE hash, st_data_t key, st_ https://github.com/ruby/ruby/blob/trunk/hash.c#L928 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; } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/