55
55
import org .truffleruby .core .format .FormatExceptionTranslator ;
56
56
import org .truffleruby .core .format .exceptions .FormatException ;
57
57
import org .truffleruby .core .format .pack .PackCompiler ;
58
+ import org .truffleruby .core .hash .HashingNodes ;
58
59
import org .truffleruby .core .kernel .KernelNodes ;
59
60
import org .truffleruby .core .kernel .KernelNodes .SameOrEqlNode ;
60
61
import org .truffleruby .core .kernel .KernelNodes .SameOrEqualNode ;
@@ -1049,20 +1050,19 @@ protected Object fillFallback(VirtualFrame frame, RubyArray array, Object[] args
1049
1050
1050
1051
}
1051
1052
1052
- @ CoreMethod ( names = "hash_internal" , visibility = Visibility . PRIVATE )
1053
- @ ReportPolymorphism
1054
- public abstract static class HashNode extends ArrayCoreMethodNode {
1053
+ @ Primitive ( name = "hash_internal" )
1054
+ @ ImportStatic ( ArrayGuards . class )
1055
+ public abstract static class HashNode extends PrimitiveArrayArgumentsNode {
1055
1056
1056
1057
private static final int CLASS_SALT = 42753062 ; // random number, stops hashes for similar values but different classes being the same, static because we want deterministic hashes
1057
1058
1058
1059
@ Specialization (limit = "storageStrategyLimit()" )
1059
1060
protected long hash (VirtualFrame frame , RubyArray array ,
1060
1061
@ Bind ("array.getStore()" ) Object store ,
1061
1062
@ CachedLibrary ("store" ) ArrayStoreLibrary stores ,
1062
- @ Cached DispatchNode toHashNode ,
1063
- @ Cached ToLongNode toLongNode ,
1064
- @ Cached IntValueProfile arraySizeProfile ,
1065
- @ Cached LoopConditionProfile loopProfile ) {
1063
+ @ Cached HashingNodes .ToHashByHashCode toHashByHashCode ,
1064
+ @ Cached @ Shared IntValueProfile arraySizeProfile ,
1065
+ @ Cached @ Shared LoopConditionProfile loopProfile ) {
1066
1066
final int size = arraySizeProfile .profile (array .size );
1067
1067
long h = getContext ().getHashing (this ).start (size );
1068
1068
h = Hashing .update (h , CLASS_SALT );
@@ -1071,8 +1071,7 @@ protected long hash(VirtualFrame frame, RubyArray array,
1071
1071
try {
1072
1072
for (; loopProfile .inject (n < size ); n ++) {
1073
1073
final Object value = stores .read (store , n );
1074
- final long valueHash = toLongNode .execute (toHashNode .call (value , "hash" ));
1075
- h = Hashing .update (h , valueHash );
1074
+ h = Hashing .update (h , toHashByHashCode .execute (value ));
1076
1075
TruffleSafepoint .poll (this );
1077
1076
}
1078
1077
} finally {
0 commit comments