17
17
import java .util .concurrent .TimeUnit ;
18
18
19
19
import com .oracle .truffle .api .dsl .CachedContext ;
20
+ import com .oracle .truffle .api .dsl .Fallback ;
20
21
import com .oracle .truffle .api .frame .Frame ;
21
22
import com .oracle .truffle .api .utilities .AssumedValue ;
22
23
import org .jcodings .specific .UTF8Encoding ;
83
84
import org .truffleruby .core .support .TypeNodes .ObjectInstanceVariablesNode ;
84
85
import org .truffleruby .core .support .TypeNodesFactory .ObjectInstanceVariablesNodeFactory ;
85
86
import org .truffleruby .core .symbol .RubySymbol ;
87
+ import org .truffleruby .core .symbol .SymbolNodes ;
86
88
import org .truffleruby .core .symbol .SymbolTable ;
87
89
import org .truffleruby .core .thread .GetCurrentRubyThreadNode ;
88
90
import org .truffleruby .core .thread .RubyThread ;
@@ -930,6 +932,7 @@ protected boolean isFrozen(Object self,
930
932
931
933
}
932
934
935
+ /** Keep consistent with {@link org.truffleruby.core.hash.HashingNodes.ToHashByHashCode} */
933
936
@ CoreMethod (names = "hash" )
934
937
public abstract static class HashNode extends CoreMethodArrayArgumentsNode {
935
938
@@ -940,37 +943,50 @@ public static HashNode create() {
940
943
public abstract Object execute (Object value );
941
944
942
945
@ Specialization
943
- protected long hash ( int value ) {
944
- return HashOperations .hashLong (value , getContext (), this );
946
+ protected long hashBoolean ( boolean value ) {
947
+ return HashOperations .hashBoolean (value , getContext (), this );
945
948
}
946
949
947
950
@ Specialization
948
- protected long hash ( long value ) {
951
+ protected long hashInt ( int value ) {
949
952
return HashOperations .hashLong (value , getContext (), this );
950
953
}
951
954
952
955
@ Specialization
953
- protected long hash ( double value ) {
954
- return HashOperations .hashDouble (value , getContext (), this );
956
+ protected long hashLong ( long value ) {
957
+ return HashOperations .hashLong (value , getContext (), this );
955
958
}
956
959
957
960
@ Specialization
958
- protected long hash ( boolean value ) {
959
- return HashOperations .hashBoolean (value , getContext (), this );
961
+ protected long hashDouble ( double value ) {
962
+ return HashOperations .hashDouble (value , getContext (), this );
960
963
}
961
964
962
965
@ Specialization
963
966
protected long hashBignum (RubyBignum value ) {
964
967
return HashOperations .hashBignum (value , getContext (), this );
965
968
}
966
969
967
- @ Specialization (guards = "!isRubyBignum(self)" )
968
- protected int hash (ImmutableRubyObject self ) {
969
- return System .identityHashCode (self );
970
+ @ Specialization
971
+ protected long hashString (RubyString value ,
972
+ @ Cached StringNodes .HashStringNode stringHashNode ) {
973
+ return stringHashNode .execute (value );
974
+ }
975
+
976
+ @ Specialization
977
+ protected long hashImmutableString (ImmutableRubyString value ,
978
+ @ Cached StringNodes .HashStringNode stringHashNode ) {
979
+ return stringHashNode .execute (value );
970
980
}
971
981
972
982
@ Specialization
973
- protected int hash (RubyDynamicObject self ) {
983
+ protected long hashSymbol (RubySymbol value ,
984
+ @ Cached SymbolNodes .HashSymbolNode symbolHashNode ) {
985
+ return symbolHashNode .execute (value );
986
+ }
987
+
988
+ @ Fallback
989
+ protected int hashOtherUsingIdentity (Object self ) {
974
990
return System .identityHashCode (self );
975
991
}
976
992
}
0 commit comments