13
13
import com .oracle .truffle .api .dsl .Cached ;
14
14
import com .oracle .truffle .api .dsl .CachedContext ;
15
15
import com .oracle .truffle .api .dsl .Fallback ;
16
+ import com .oracle .truffle .api .dsl .GenerateUncached ;
16
17
import com .oracle .truffle .api .dsl .Specialization ;
17
18
import org .truffleruby .RubyContext ;
18
19
import org .truffleruby .RubyLanguage ;
19
20
import org .truffleruby .core .basicobject .BasicObjectNodes .ObjectIDNode ;
20
21
import org .truffleruby .core .cast .ToRubyIntegerNode ;
22
+ import org .truffleruby .core .hash .HashingNodesFactory .HashCastResultNodeGen ;
23
+ import org .truffleruby .core .hash .HashingNodesFactory .ToHashByIdentityNodeGen ;
21
24
import org .truffleruby .core .numeric .BigIntegerOps ;
22
25
import org .truffleruby .core .numeric .RubyBignum ;
23
26
import org .truffleruby .core .string .RubyString ;
24
27
import org .truffleruby .core .string .StringNodes ;
25
28
import org .truffleruby .core .symbol .RubySymbol ;
26
29
import org .truffleruby .core .symbol .SymbolNodes ;
27
30
import org .truffleruby .core .string .ImmutableRubyString ;
31
+ import org .truffleruby .language .RubyBaseNode ;
28
32
import org .truffleruby .language .RubyContextNode ;
29
33
import org .truffleruby .language .dispatch .DispatchNode ;
30
34
@@ -137,7 +141,16 @@ private int castResult(Object value) {
137
141
138
142
}
139
143
140
- public abstract static class ToHashByIdentity extends RubyContextNode {
144
+ @ GenerateUncached
145
+ public abstract static class ToHashByIdentity extends RubyBaseNode {
146
+
147
+ public static ToHashByIdentity create () {
148
+ return ToHashByIdentityNodeGen .create ();
149
+ }
150
+
151
+ public static ToHashByIdentity getUncached () {
152
+ return ToHashByIdentityNodeGen .getUncached ();
153
+ }
141
154
142
155
public abstract int execute (Object key );
143
156
@@ -147,19 +160,15 @@ protected int toHashByIdentity(Object hashed,
147
160
@ Cached HashCastResultNode hashCastResultNode ) {
148
161
return hashCastResultNode .execute (objectIDNode .execute (hashed ));
149
162
}
150
-
151
163
}
152
164
153
-
154
- public abstract static class HashCastResultNode extends RubyContextNode {
155
-
156
- @ Child private ToRubyIntegerNode toRubyInteger ;
157
- @ Child private HashCastResultNode hashCastResultNode ;
165
+ @ GenerateUncached
166
+ public abstract static class HashCastResultNode extends RubyBaseNode {
158
167
159
168
public abstract int execute (Object key );
160
169
161
170
public static HashCastResultNode create () {
162
- return HashingNodesFactory . HashCastResultNodeGen .create ();
171
+ return HashCastResultNodeGen .create ();
163
172
}
164
173
165
174
@ Specialization
@@ -177,24 +186,11 @@ protected int castBignum(RubyBignum hashed) {
177
186
return BigIntegerOps .hashCode (hashed );
178
187
}
179
188
180
- @ Fallback
181
- protected int castOther (Object hashed ) {
182
- if (toRubyInteger == null ) {
183
- CompilerDirectives .transferToInterpreterAndInvalidate ();
184
- toRubyInteger = insert (ToRubyIntegerNode .create ());
185
- }
186
- final Object coercedHashedObject = toRubyInteger .execute (hashed );
187
- return castCoerced (coercedHashedObject );
189
+ @ Specialization (guards = "!isRubyInteger(hashed)" )
190
+ protected int castOther (Object hashed ,
191
+ @ Cached ToRubyIntegerNode toRubyInteger ,
192
+ @ Cached HashCastResultNode hashCastResult ) {
193
+ return hashCastResult .execute (toRubyInteger .execute (hashed ));
188
194
}
189
-
190
- private int castCoerced (Object coerced ) {
191
- if (hashCastResultNode == null ) {
192
- CompilerDirectives .transferToInterpreterAndInvalidate ();
193
- hashCastResultNode = insert (HashCastResultNode .create ());
194
- }
195
- return hashCastResultNode .execute (coerced );
196
- }
197
-
198
195
}
199
-
200
196
}
0 commit comments