File tree 5 files changed +32
-1
lines changed
5 files changed +32
-1
lines changed Original file line number Diff line number Diff line change
1
+ Thu Jan 22 16:45:24 2015 Eric Wong <
[email protected] >
2
+
3
+ * st.c (st_numhash): mix float value for flonum
4
+ * hash.c (rb_any_hash): ditto
5
+ * benchmark/bm_hash_aref_flo.rb: new benchmark
6
+ * benchmark/bm_hash_ident_flo.rb: ditto
7
+ [Bug #10761]
8
+
1
9
Wed Jan 21 22:33:51 2015 Akinori MUSHA <
[email protected] >
2
10
3
11
* misc/ruby-electric.el: Import version 2.2.1 from
Original file line number Diff line number Diff line change
1
+ h = { }
2
+ strs = ( 1 ..10000 ) . to_a . map! ( &:to_f )
3
+ strs . each { |s | h [ s ] = s }
4
+ 50 . times { strs . each { |s | h [ s ] } }
Original file line number Diff line number Diff line change
1
+ h = { } . compare_by_identity
2
+ strs = ( 1 ..10000 ) . to_a . map! ( &:to_f )
3
+ strs . each { |s | h [ s ] = s }
4
+ 50 . times { strs . each { |s | h [ s ] } }
Original file line number Diff line number Diff line change @@ -137,7 +137,13 @@ rb_any_hash(VALUE a)
137
137
138
138
if (SPECIAL_CONST_P (a )) {
139
139
if (a == Qundef ) return 0 ;
140
- if (STATIC_SYM_P (a )) a >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT );
140
+ if (STATIC_SYM_P (a )) {
141
+ a >>= (RUBY_SPECIAL_SHIFT + ID_SCOPE_SHIFT );
142
+ }
143
+ else if (FLONUM_P (a )) {
144
+ /* prevent pathological behavior: [Bug #10761] */
145
+ a = (st_index_t )rb_float_value (a );
146
+ }
141
147
hnum = rb_objid_hash ((st_index_t )a );
142
148
}
143
149
else if (BUILTIN_TYPE (a ) == T_STRING ) {
Original file line number Diff line number Diff line change @@ -1761,6 +1761,15 @@ st_numhash(st_data_t n)
1761
1761
* - (n << 3) was finally added to avoid losing bits for fixnums
1762
1762
* - avoid expensive modulo instructions, it is currently only
1763
1763
* shifts and bitmask operations.
1764
+ * - flonum (on 64-bit) is pathologically bad, mix the actual
1765
+ * float value in, but do not use the float value as-is since
1766
+ * many integers get interpreted as 2.0 or -2.0 [Bug #10761]
1764
1767
*/
1768
+ #ifdef USE_FLONUM /* RUBY */
1769
+ if (FLONUM_P (n )) {
1770
+ n ^= (st_data_t )rb_float_value (n );
1771
+ }
1772
+ #endif
1773
+
1765
1774
return (st_index_t )((n >>(RUBY_SPECIAL_SHIFT + 3 )|(n <<3 )) ^ (n >>3 ));
1766
1775
}
You can’t perform that action at this time.
0 commit comments