Skip to content

Commit 3823a96

Browse files
committed
don't use regex matching to compute reverse method name
1 parent e623945 commit 3823a96

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallBinaryNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ public static LookupAndCallBinaryNode create(String name) {
110110
return LookupAndCallBinaryNodeGen.create(name, null, null);
111111
}
112112

113-
public static LookupAndCallBinaryNode createReversible(String name, Supplier<NotImplementedHandler> handlerFactory) {
114-
assert name.startsWith("__");
115-
return LookupAndCallBinaryNodeGen.create(name, name.replaceFirst("__", "__r"), handlerFactory);
113+
public static LookupAndCallBinaryNode createReversible(String name, String reverseName, Supplier<NotImplementedHandler> handlerFactory) {
114+
assert name.startsWith("__") && reverseName.startsWith("__r");
115+
return LookupAndCallBinaryNodeGen.create(name, reverseName, handlerFactory);
116116
}
117117

118118
public static LookupAndCallBinaryNode create(String name, String rname) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryArithmetic.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ public enum BinaryArithmetic {
6767
Pow(SpecialMethodNames.__POW__, "**");
6868

6969
private final String methodName;
70+
private final String reverseMethodName;
7071
private final String operator;
7172
private final Supplier<NotImplementedHandler> notImplementedHandler;
7273

7374
BinaryArithmetic(String methodName, String operator) {
7475
this.methodName = methodName;
76+
assert methodName.startsWith("__");
77+
this.reverseMethodName = "__r" + methodName.substring(2);
7578
this.operator = operator;
7679
this.notImplementedHandler = () -> new NotImplementedHandler() {
7780
@Override
@@ -112,10 +115,10 @@ public NodeCost getCost() {
112115
}
113116

114117
public ExpressionNode create(ExpressionNode left, ExpressionNode right) {
115-
return new BinaryArithmeticExpression(LookupAndCallBinaryNode.createReversible(methodName, notImplementedHandler), left, right);
118+
return new BinaryArithmeticExpression(LookupAndCallBinaryNode.createReversible(methodName, reverseMethodName, notImplementedHandler), left, right);
116119
}
117120

118121
public LookupAndCallBinaryNode create() {
119-
return LookupAndCallBinaryNode.createReversible(methodName, notImplementedHandler);
122+
return LookupAndCallBinaryNode.createReversible(methodName, reverseMethodName, notImplementedHandler);
120123
}
121124
}

0 commit comments

Comments
 (0)