diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-04-23 12:10:52 -0700 |
---|---|---|
committer | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-04-23 14:21:15 -0700 |
commit | 75061f46ae646e821e9228caa5e3b7f23fa609f0 (patch) | |
tree | 9ea4054d0594295bfcf347c4a820fe4b3508ec24 /hash.c | |
parent | cf930985da1ae15b66577ec8286e54ad04ccda78 (diff) | |
download | ruby-75061f46ae646e821e9228caa5e3b7f23fa609f0.tar.gz |
Fix complex hash keys to work with compaction
For example when an array containing objects is a hash key, the contents
of the array may move which can cause the hash value for the array to
change. This commit makes the default `hash` value based off the
object id, so the hash value will remain stable.
Fixes test/shell/test_command_processor.rb
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -272,7 +272,11 @@ rb_objid_hash(st_index_t index) static st_index_t objid_hash(VALUE obj) { - return (st_index_t)st_index_hash((st_index_t)obj); +#if SIZEOF_LONG == SIZEOF_VOIDP + return (st_index_t)st_index_hash((st_index_t)NUM2LONG(rb_obj_id(obj))); +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP + return (st_index_t)st_index_hash((st_index_t)NUM2LL(rb_obj_id(obj))); +#endif } VALUE |