9
9
*/
10
10
package org .truffleruby .core .hash ;
11
11
12
+ import com .oracle .truffle .api .dsl .Cached ;
12
13
import org .truffleruby .core .string .RubyString ;
13
14
import org .truffleruby .language .ImmutableRubyString ;
14
15
import org .truffleruby .language .RubyContextNode ;
15
16
import org .truffleruby .language .dispatch .DispatchNode ;
16
17
import org .truffleruby .language .library .RubyLibrary ;
17
18
18
- import com .oracle .truffle .api .CompilerDirectives ;
19
19
import com .oracle .truffle .api .dsl .Specialization ;
20
20
import com .oracle .truffle .api .library .CachedLibrary ;
21
- import org .truffleruby .language .library .RubyStringLibrary ;
22
21
23
22
public abstract class FreezeHashKeyIfNeededNode extends RubyContextNode {
24
23
25
- @ Child private DispatchNode dupNode ;
26
-
27
24
public abstract Object executeFreezeIfNeeded (Object key , boolean compareByIdentity );
28
25
29
26
@ Specialization
30
- protected Object alreadyFrozen (ImmutableRubyString string , boolean compareByIdentity ) {
27
+ protected Object immutable (ImmutableRubyString string , boolean compareByIdentity ) {
31
28
return string ;
32
29
}
33
30
34
31
@ Specialization (
35
- guards = { "strings.isRubyString(string)" , " rubyLibrary.isFrozen(string)" } ,
32
+ guards = " rubyLibrary.isFrozen(string)" ,
36
33
limit = "getRubyLibraryCacheLimit()" )
37
- protected Object alreadyFrozen (Object string , boolean compareByIdentity ,
38
- @ CachedLibrary (limit = "2" ) RubyStringLibrary strings ,
34
+ protected Object alreadyFrozen (RubyString string , boolean compareByIdentity ,
39
35
@ CachedLibrary ("string" ) RubyLibrary rubyLibrary ) {
40
36
return string ;
41
37
}
42
38
43
39
@ Specialization (
44
- guards = { "strings.isRubyString(string)" , " !rubyLibrary.isFrozen(string)" , "!compareByIdentity" },
40
+ guards = { "!rubyLibrary.isFrozen(string)" , "!compareByIdentity" },
45
41
limit = "getRubyLibraryCacheLimit()" )
46
- protected Object dupAndFreeze (Object string , boolean compareByIdentity ,
47
- @ CachedLibrary (limit = "2" ) RubyStringLibrary strings ,
42
+ protected Object dupAndFreeze (RubyString string , boolean compareByIdentity ,
48
43
@ CachedLibrary ("string" ) RubyLibrary rubyLibrary ,
49
- @ CachedLibrary (limit = "getRubyLibraryCacheLimit()" ) RubyLibrary rubyLibraryObject ) {
50
- final Object object = dup (string );
44
+ @ CachedLibrary (limit = "getRubyLibraryCacheLimit()" ) RubyLibrary rubyLibraryObject ,
45
+ @ Cached DispatchNode dupNode ) {
46
+ final Object object = dupNode .call (string , "dup" );
51
47
rubyLibraryObject .freeze (object );
52
48
return object ;
53
49
}
54
50
55
51
@ Specialization (
56
- guards = { "strings.isRubyString(string)" , " !rubyLibrary.isFrozen(string)" , "compareByIdentity" },
52
+ guards = { "!rubyLibrary.isFrozen(string)" , "compareByIdentity" },
57
53
limit = "getRubyLibraryCacheLimit()" )
58
54
protected Object compareByIdentity (RubyString string , boolean compareByIdentity ,
59
- @ CachedLibrary (limit = "2" ) RubyStringLibrary strings ,
60
55
@ CachedLibrary ("string" ) RubyLibrary rubyLibrary ) {
61
56
return string ;
62
57
}
@@ -66,14 +61,4 @@ protected Object passThrough(Object value, boolean compareByIdentity) {
66
61
return value ;
67
62
}
68
63
69
-
70
- private Object dup (Object value ) {
71
- if (dupNode == null ) {
72
- CompilerDirectives .transferToInterpreterAndInvalidate ();
73
- dupNode = insert (DispatchNode .create ());
74
- }
75
- return dupNode .call (value , "dup" );
76
- }
77
-
78
-
79
64
}
0 commit comments