@@ -86,7 +86,11 @@ public class IRBuilder {
86
86
static final Operand [] NO_ARGS = new Operand []{};
87
87
static final UnexecutableNil U_NIL = UnexecutableNil .U_NIL ;
88
88
89
- public static final String USING_METHOD = "using" ;
89
+ public static final ByteList USING_METHOD = new ByteList (new byte [] {'u' , 's' , 'i' , 'n' , 'g' });
90
+ public static final ByteList DEFINE_METHOD_METHOD = new ByteList (new byte [] {'d' , 'e' , 'f' , 'i' , 'n' , 'e' , '_' , 'm' , 'e' , 't' , 'h' , 'o' , 'd' });
91
+ public static final ByteList FREEZE_METHOD = new ByteList (new byte [] {'f' , 'r' , 'e' , 'e' , 'z' , 'e' });
92
+ public static final ByteList AREF_METHOD = new ByteList (new byte [] {'[' , ']' });
93
+ public static final ByteList NEW_METHOD = new ByteList (new byte [] {'n' , 'e' , 'w' });
90
94
91
95
public static Node buildAST (boolean isCommandLineScript , String arg ) {
92
96
Ruby ruby = Ruby .getGlobalRuntime ();
@@ -1044,7 +1048,7 @@ public Operand buildCall(Variable result, CallNode callNode) {
1044
1048
Node receiverNode = callNode .getReceiverNode ();
1045
1049
1046
1050
// Frozen string optimization: check for "string".freeze
1047
- if (receiverNode instanceof StrNode && callNode . getName (). equals ( "freeze" )) {
1051
+ if (receiverNode instanceof StrNode && FREEZE_METHOD . equals ( callNode . getByteName () )) {
1048
1052
StrNode asString = (StrNode ) receiverNode ;
1049
1053
return new FrozenString (asString .getValue (), asString .getCodeRange (), scope .getFileName (), asString .getPosition ().getLine ());
1050
1054
}
@@ -1056,9 +1060,8 @@ public Operand buildCall(Variable result, CallNode callNode) {
1056
1060
1057
1061
// obj["string"] optimization for Hash
1058
1062
ArrayNode argsAry ;
1059
- if (
1060
- !callNode .isLazy () &&
1061
- callNode .getName ().equals ("[]" ) &&
1063
+ if (!callNode .isLazy () &&
1064
+ AREF_METHOD .equals (callNode .getByteName ()) &&
1062
1065
callNode .getArgsNode () instanceof ArrayNode &&
1063
1066
(argsAry = (ArrayNode ) callNode .getArgsNode ()).size () == 1 &&
1064
1067
argsAry .get (0 ) instanceof StrNode &&
@@ -1082,19 +1085,20 @@ public Operand buildCall(Variable result, CallNode callNode) {
1082
1085
1083
1086
CallInstr callInstr ;
1084
1087
Operand block ;
1088
+ ByteList name = callNode .getByteName ();
1085
1089
if (keywordArgs != null ) {
1086
1090
Operand [] args = buildCallArgsExcept (callNode .getArgsNode (), keywordArgs );
1087
1091
List <KeyValuePair <Operand , Operand >> kwargs = buildKeywordArguments (keywordArgs );
1088
1092
block = setupCallClosure (callNode .getIterNode ());
1089
- callInstr = CallInstr .createWithKwargs (scope , CallType .NORMAL , result , callNode . getByteName () , receiver , args , block , kwargs );
1093
+ callInstr = CallInstr .createWithKwargs (scope , CallType .NORMAL , result , name , receiver , args , block , kwargs );
1090
1094
} else {
1091
1095
Operand [] args = setupCallArgs (callNode .getArgsNode ());
1092
1096
block = setupCallClosure (callNode .getIterNode ());
1093
- callInstr = CallInstr .create (scope , result , callNode . getByteName () , receiver , args , block );
1097
+ callInstr = CallInstr .create (scope , result , name , receiver , args , block );
1094
1098
}
1095
1099
1096
1100
determineIfWeNeedLineNumber (callNode );
1097
- determineIfProcNew (receiverNode , callNode . getName () , callInstr );
1101
+ determineIfProcNew (receiverNode , name , callInstr );
1098
1102
receiveBreakException (block , callInstr );
1099
1103
1100
1104
if (callNode .isLazy ()) {
@@ -1115,9 +1119,9 @@ private List<KeyValuePair<Operand, Operand>> buildKeywordArguments(HashNode keyw
1115
1119
return kwargs ;
1116
1120
}
1117
1121
1118
- private void determineIfProcNew (Node receiverNode , String name , CallInstr callInstr ) {
1122
+ private void determineIfProcNew (Node receiverNode , ByteList name , CallInstr callInstr ) {
1119
1123
// This is to support the ugly Proc.new with no block, which must see caller's frame
1120
- if (name .equals ("new" ) && receiverNode instanceof ConstNode && ((ConstNode )receiverNode ).getName ().equals ("Proc" )) {
1124
+ if (NEW_METHOD .equals (name ) && receiverNode instanceof ConstNode && ((ConstNode )receiverNode ).getName ().equals ("Proc" )) {
1121
1125
callInstr .setProcNew (true );
1122
1126
}
1123
1127
}
@@ -1711,7 +1715,7 @@ public Operand buildGetDefinition(Node node) {
1711
1715
IS_DEFINED_METHOD ,
1712
1716
new Operand [] {
1713
1717
buildSelf (),
1714
- new FrozenString (((VCallNode ) node ).getName ()),
1718
+ new FrozenString (((VCallNode ) node ).getByteName ()),
1715
1719
manager .getFalse (),
1716
1720
new FrozenString (DefinedMessage .METHOD .getText ())
1717
1721
}
@@ -1829,7 +1833,7 @@ public Operand run() {
1829
1833
IS_DEFINED_METHOD ,
1830
1834
new Operand []{
1831
1835
buildSelf (),
1832
- new FrozenString (((FCallNode ) node ).getName ()),
1836
+ new FrozenString (((FCallNode ) node ).getByteName ()),
1833
1837
manager .getFalse (),
1834
1838
new FrozenString (DefinedMessage .METHOD .getText ())
1835
1839
}
@@ -1855,7 +1859,7 @@ public Operand run() {
1855
1859
IS_DEFINED_CALL ,
1856
1860
new Operand []{
1857
1861
build (callNode .getReceiverNode ()),
1858
- new StringLiteral (callNode .getName ()),
1862
+ new StringLiteral (callNode .getByteName ()),
1859
1863
new FrozenString (DefinedMessage .METHOD .getText ())
1860
1864
}
1861
1865
)
@@ -1903,7 +1907,7 @@ public Operand run() {
1903
1907
IS_DEFINED_METHOD ,
1904
1908
new Operand [] {
1905
1909
receiver ,
1906
- new StringLiteral (attrAssign .getName ()),
1910
+ new StringLiteral (attrAssign .getByteName ()),
1907
1911
manager .getTrue (),
1908
1912
new FrozenString (DefinedMessage .METHOD .getText ())
1909
1913
}
@@ -2688,11 +2692,11 @@ public Operand buildFCall(Variable result, FCallNode fcallNode) {
2688
2692
} else {
2689
2693
Operand [] args = setupCallArgs (callArgsNode );
2690
2694
block = setupCallClosure (fcallNode .getIterNode ());
2691
- determineIfMaybeUsingMethod (fcallNode .getName (), args );
2695
+ determineIfMaybeUsingMethod (fcallNode .getByteName (), args );
2692
2696
2693
2697
// We will stuff away the iters AST source into the closure in the hope we can convert
2694
2698
// this closure to a method.
2695
- if (fcallNode . getName (). equals ( "define_method" ) && block instanceof WrappedIRClosure ) {
2699
+ if (DEFINE_METHOD_METHOD . equals ( fcallNode . getByteName () ) && block instanceof WrappedIRClosure ) {
2696
2700
IRClosure closure = ((WrappedIRClosure ) block ).getClosure ();
2697
2701
2698
2702
// To convert to a method we need its variable scoping to appear like a normal method.
@@ -2727,7 +2731,7 @@ private Operand setupCallClosure(Node node) {
2727
2731
}
2728
2732
2729
2733
// FIXME: This needs to be called on super/zsuper too
2730
- private void determineIfMaybeUsingMethod (String methodName , Operand [] args ) {
2734
+ private void determineIfMaybeUsingMethod (ByteList methodName , Operand [] args ) {
2731
2735
IRScope outerScope = scope .getNearestTopLocalVariableScope ();
2732
2736
2733
2737
// 'using single_mod_arg' possible nearly everywhere but method scopes.
0 commit comments