19
19
import com .oracle .truffle .api .strings .TruffleString ;
20
20
import org .graalvm .shadowed .org .joni .NameEntry ;
21
21
import org .truffleruby .annotations .CoreMethod ;
22
+ import org .truffleruby .annotations .Split ;
22
23
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
23
24
import org .truffleruby .annotations .CoreModule ;
24
25
import org .truffleruby .annotations .Primitive ;
43
44
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
44
45
import com .oracle .truffle .api .dsl .Cached ;
45
46
import com .oracle .truffle .api .dsl .Cached .Shared ;
46
- import com .oracle .truffle .api .dsl .Fallback ;
47
47
import com .oracle .truffle .api .dsl .Specialization ;
48
48
49
49
@ CoreModule (value = "Regexp" , isClass = true )
@@ -58,7 +58,7 @@ int hash(RubyRegexp regexp) {
58
58
}
59
59
}
60
60
61
- @ CoreMethod (names = { "quote" , "escape" }, onSingleton = true , required = 1 )
61
+ @ CoreMethod (names = { "quote" , "escape" }, onSingleton = true , required = 1 , split = Split . ALWAYS )
62
62
public abstract static class QuoteNode extends CoreMethodArrayArgumentsNode {
63
63
64
64
public abstract RubyString execute (Object raw );
@@ -68,25 +68,45 @@ public static QuoteNode create() {
68
68
return RegexpNodesFactory .QuoteNodeFactory .create (null );
69
69
}
70
70
71
- @ Specialization (guards = "libRaw.isRubyString(raw)" , limit = "1" )
71
+ @ Specialization (
72
+ guards = {
73
+ "libRaw.isRubyString(raw)" ,
74
+ "rawEqualNode.execute(node, libRaw, raw, cachedRaw, cachedRawEnc)" },
75
+ limit = "getDefaultCacheLimit()" )
76
+ static RubyString quoteStringCached (Object raw ,
77
+ @ Cached @ Shared RubyStringLibrary libRaw ,
78
+ @ Cached ("asTruffleStringUncached(raw)" ) TruffleString cachedRaw ,
79
+ @ Cached ("libRaw.getEncoding(raw)" ) RubyEncoding cachedRawEnc ,
80
+ @ Cached StringHelperNodes .EqualSameEncodingNode rawEqualNode ,
81
+ @ Bind ("this" ) Node node ,
82
+ @ Cached ("quote(libRaw, raw)" ) RubyString quotedString ) {
83
+ return quotedString ;
84
+ }
85
+
86
+ @ Specialization (replaces = "quoteStringCached" , guards = "libRaw.isRubyString(raw)" )
72
87
RubyString quoteString (Object raw ,
73
- @ Cached RubyStringLibrary libRaw ) {
74
- return createString ( ClassicRegexp . quote19 ( new ATStringWithEncoding ( libRaw , raw )) );
88
+ @ Cached @ Shared RubyStringLibrary libRaw ) {
89
+ return quote ( libRaw , raw );
75
90
}
76
91
77
92
@ Specialization
78
93
RubyString quoteSymbol (RubySymbol raw ) {
79
94
return createString (ClassicRegexp .quote19 (new ATStringWithEncoding (raw .tstring , raw .encoding )));
80
95
}
81
96
82
- @ Fallback
83
- static RubyString quote (Object raw ,
97
+ @ Specialization (guards = { "!libRaw.isRubyString(raw)" , "!isRubySymbol(raw)" })
98
+ static RubyString quoteGeneric (Object raw ,
99
+ @ Cached @ Shared RubyStringLibrary libRaw ,
84
100
@ Cached ToStrNode toStrNode ,
85
101
@ Cached QuoteNode recursive ,
86
102
@ Bind ("this" ) Node node ) {
87
103
return recursive .execute (toStrNode .execute (node , raw ));
88
104
}
89
105
106
+ RubyString quote (RubyStringLibrary strings , Object string ) {
107
+ return createString (ClassicRegexp .quote19 (new ATStringWithEncoding (strings , string )));
108
+ }
109
+
90
110
}
91
111
92
112
@ CoreMethod (names = "source" )
0 commit comments