Skip to content

Commit a1428d7

Browse files
committed
optimization - migrate from INVOKEINTERFACE to INVOKEVIRTUAL
1 parent 4557050 commit a1428d7

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/main/java/org/perlonjava/codegen/EmitOperator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,8 @@ public static void handleScalarContext(EmitterVisitor emitterVisitor, Node node)
410410
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className,
411411
"scalar", "()" + RuntimeTypeConstants.SCALAR_TYPE, false);
412412
} else {
413-
// For unknown types or any other RuntimeDataProvider implementations
414-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, RuntimeTypeConstants.DATA_PROVIDER_INTERFACE,
415-
"scalar", "()" + RuntimeTypeConstants.SCALAR_TYPE, true);
413+
// For unknown types
414+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", false);
416415
}
417416
}
418417

src/main/java/org/perlonjava/codegen/EmitRegex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private static void emitMatchRegex(EmitterVisitor emitterVisitor) {
196196
// Handle the result based on context type
197197
if (emitterVisitor.ctx.contextType == RuntimeContextType.SCALAR) {
198198
// Convert result to Scalar if in scalar context
199-
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", true);
199+
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", false);
200200
} else if (emitterVisitor.ctx.contextType == RuntimeContextType.VOID) {
201201
// Discard result if in void context
202202
emitterVisitor.ctx.mv.visitInsn(Opcodes.POP);

src/main/java/org/perlonjava/codegen/EmitVariable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static void handleVariableOperator(EmitterVisitor emitterVisitor, OperatorNode n
133133
}
134134
if (emitterVisitor.ctx.contextType == RuntimeContextType.SCALAR && !sigil.equals("$")) {
135135
// scalar context: transform the value in the stack to scalar
136-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", true);
136+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", false);
137137
}
138138
emitterVisitor.ctx.logDebug("GETVAR end " + varIndex);
139139
return;
@@ -469,7 +469,7 @@ static void handleMyOperator(EmitterVisitor emitterVisitor, OperatorNode node) {
469469
emitterVisitor.ctx.mv.visitVarInsn(Opcodes.ASTORE, varIndex);
470470
if (emitterVisitor.ctx.contextType == RuntimeContextType.SCALAR && !sigil.equals("$")) {
471471
// scalar context: transform the value in the stack to scalar
472-
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", true);
472+
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", "scalar", "()Lorg/perlonjava/runtime/RuntimeScalar;", false);
473473
}
474474
return;
475475
}

src/main/java/org/perlonjava/operators/OperatorHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,24 @@ public class OperatorHandler {
190190
"(Lorg/perlonjava/runtime/RuntimeList;Lorg/perlonjava/runtime/RuntimeScalar;I)Lorg/perlonjava/runtime/RuntimeList;");
191191

192192
operatorHandlers.put("scalar",
193-
new OperatorHandler("org/perlonjava/runtime/RuntimeDataProvider",
193+
new OperatorHandler("org/perlonjava/runtime/RuntimeBaseEntity",
194194
"scalar",
195-
Opcodes.INVOKEINTERFACE,
195+
Opcodes.INVOKEVIRTUAL,
196196
"()Lorg/perlonjava/runtime/RuntimeScalar;"));
197197
operatorHandlers.put("each",
198-
new OperatorHandler("org/perlonjava/runtime/RuntimeDataProvider",
198+
new OperatorHandler("org/perlonjava/runtime/RuntimeBaseEntity",
199199
"each",
200-
Opcodes.INVOKEINTERFACE,
200+
Opcodes.INVOKEVIRTUAL,
201201
"()Lorg/perlonjava/runtime/RuntimeList;"));
202202
operatorHandlers.put("keys",
203-
new OperatorHandler("org/perlonjava/runtime/RuntimeDataProvider",
203+
new OperatorHandler("org/perlonjava/runtime/RuntimeBaseEntity",
204204
"keys",
205-
Opcodes.INVOKEINTERFACE,
205+
Opcodes.INVOKEVIRTUAL,
206206
"()Lorg/perlonjava/runtime/RuntimeArray;"));
207207
operatorHandlers.put("values",
208-
new OperatorHandler("org/perlonjava/runtime/RuntimeDataProvider",
208+
new OperatorHandler("org/perlonjava/runtime/RuntimeBaseEntity",
209209
"values",
210-
Opcodes.INVOKEINTERFACE,
210+
Opcodes.INVOKEVIRTUAL,
211211
"()Lorg/perlonjava/runtime/RuntimeArray;"));
212212

213213

0 commit comments

Comments
 (0)