fix flonum hashing regression from r45384
* st.c (st_numhash): mix float value for flonum * hash.c (rb_any_hash): ditto * benchmark/bm_hash_aref_flo.rb: new benchmark * benchmark/bm_hash_ident_flo.rb: ditto [Bug #10761] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c73f2d28b4
commit
6d56fd067e
@ -1,3 +1,11 @@
|
||||
Thu Jan 22 16:45:24 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* st.c (st_numhash): mix float value for flonum
|
||||
* hash.c (rb_any_hash): ditto
|
||||
* benchmark/bm_hash_aref_flo.rb: new benchmark
|
||||
* benchmark/bm_hash_ident_flo.rb: ditto
|
||||
[Bug #10761]
|
||||
|
||||
Wed Jan 21 22:33:51 2015 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* misc/ruby-electric.el: Import version 2.2.1 from
|
||||
|
4
benchmark/bm_hash_aref_flo.rb
Normal file
4
benchmark/bm_hash_aref_flo.rb
Normal file
@ -0,0 +1,4 @@
|
||||
h = {}
|
||||
strs = (1..10000).to_a.map!(&:to_f)
|
||||
strs.each { |s| h[s] = s }
|
||||
50.times { strs.each { |s| h[s] } }
|
4
benchmark/bm_hash_ident_flo.rb
Normal file
4
benchmark/bm_hash_ident_flo.rb
Normal file
@ -0,0 +1,4 @@
|
||||
h = {}.compare_by_identity
|
||||
strs = (1..10000).to_a.map!(&:to_f)
|
||||
strs.each { |s| h[s] = s }
|
||||
50.times { strs.each { |s| h[s] } }
|
8
hash.c
8
hash.c
@ -137,7 +137,13 @@ rb_any_hash(VALUE a)
|
||||
|
||||
if (SPECIAL_CONST_P(a)) {
|
||||
if (a == Qundef) return 0;
|
||||
if (STATIC_SYM_P(a)) a >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT);
|
||||
if (STATIC_SYM_P(a)) {
|
||||
a >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT);
|
||||
}
|
||||
else if (FLONUM_P(a)) {
|
||||
/* prevent pathological behavior: [Bug #10761] */
|
||||
a = (st_index_t)rb_float_value(a);
|
||||
}
|
||||
hnum = rb_objid_hash((st_index_t)a);
|
||||
}
|
||||
else if (BUILTIN_TYPE(a) == T_STRING) {
|
||||
|
9
st.c
9
st.c
@ -1761,6 +1761,15 @@ st_numhash(st_data_t n)
|
||||
* - (n << 3) was finally added to avoid losing bits for fixnums
|
||||
* - avoid expensive modulo instructions, it is currently only
|
||||
* shifts and bitmask operations.
|
||||
* - flonum (on 64-bit) is pathologically bad, mix the actual
|
||||
* float value in, but do not use the float value as-is since
|
||||
* many integers get interpreted as 2.0 or -2.0 [Bug #10761]
|
||||
*/
|
||||
#ifdef USE_FLONUM /* RUBY */
|
||||
if (FLONUM_P(n)) {
|
||||
n ^= (st_data_t)rb_float_value(n);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (st_index_t)((n>>(RUBY_SPECIAL_SHIFT+3)|(n<<3)) ^ (n>>3));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user