groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: minor edits
Date Tue, 28 Jan 2020 23:09:18 GMT
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 61ee9c9  minor edits
61ee9c9 is described below

commit 61ee9c9fa31cef2adb0ef0c8a5558f29ab1ec82e
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Tue Jan 28 16:56:28 2020 -0600

    minor edits
---
 .../groovy/classgen/AsmClassGenerator.java         | 28 +++++++---------------
 .../classgen/asm/OptimizingStatementWriter.java    | 11 +++++----
 2 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index beeaade..f8ca958 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -432,31 +432,21 @@ public class AsmClassGenerator extends ClassGenerator {
         controller.getCallSiteWriter().makeSiteEntry();
 
         MethodVisitor mv = controller.getMethodVisitor();
-        ClassNode superClass = controller.getClassNode().getSuperClass();
         if (isConstructor && (code == null || !((ConstructorNode) node).firstStatementIsSpecialConstructorCall()))
{
             boolean hasCallToSuper = false;
-            if (code != null && controller.getClassNode() instanceof InnerClassNode)
{
-                // if the class not is an inner class node, there are chances that the call
to super is already added
-                // so we must ensure not to add it twice (see GROOVY-4471)
+            if (code != null && isInnerClass()) {
+                // GROOVY-4471: if the class is an inner class node, there are chances that
+                // the call to super is already added so we must ensure not to add it twice
                 if (code instanceof BlockStatement) {
-                    for (Statement statement : ((BlockStatement) code).getStatements()) {
-                        if (statement instanceof ExpressionStatement) {
-                            Expression expression = ((ExpressionStatement) statement).getExpression();
-                            if (expression instanceof ConstructorCallExpression) {
-                                ConstructorCallExpression call = (ConstructorCallExpression)
expression;
-                                if (call.isSuperCall()) {
-                                    hasCallToSuper = true;
-                                    break;
-                                }
-                            }
-                        }
-                    }
+                    hasCallToSuper = ((BlockStatement) code).getStatements().stream()
+                        .map(statement -> statement instanceof ExpressionStatement ? ((ExpressionStatement)
statement).getExpression() : null)
+                        .anyMatch(expression -> expression instanceof ConstructorCallExpression
&& ((ConstructorCallExpression) expression).isSuperCall());
                 }
             }
             if (!hasCallToSuper) {
                 // invokes the super class constructor
                 mv.visitVarInsn(ALOAD, 0);
-                mv.visitMethodInsn(INVOKESPECIAL, BytecodeHelper.getClassInternalName(superClass),
"<init>", "()V", false);
+                mv.visitMethodInsn(INVOKESPECIAL, controller.getInternalBaseClassName(),
"<init>", "()V", false);
             }
         }
 
@@ -2129,8 +2119,8 @@ public class AsmClassGenerator extends ClassGenerator {
         return isThisExpression(expression) || isSuperExpression(expression);
     }
 
-    private static boolean isVargs(final Parameter[] params) {
-        return (params.length > 0 && params[params.length - 1].getType().isArray());
+    private static boolean isVargs(final Parameter[] parameters) {
+        return (parameters.length > 0 && parameters[parameters.length - 1].getType().isArray());
     }
 
     public boolean addInnerClass(final ClassNode innerClass) {
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
index f6d3d95..d905a33 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
@@ -88,6 +88,8 @@ import static org.objectweb.asm.Opcodes.INVOKEINTERFACE;
 
 public class OptimizingStatementWriter extends StatementWriter {
 
+    private static final MethodCaller disabledStandardMetaClass = MethodCaller.newStatic(BytecodeInterface8.class,
"disabledStandardMetaClass");
+
     // values correspond to BinaryExpressionMultiTypeDispatcher.typeMapKeyNames
     private static final MethodCaller[] guards = {
         null,
@@ -101,17 +103,17 @@ public class OptimizingStatementWriter extends StatementWriter {
         MethodCaller.newStatic(BytecodeInterface8.class, "isOrigZ"),
     };
 
-    private static final MethodCaller disabledStandardMetaClass = MethodCaller.newStatic(BytecodeInterface8.class,
"disabledStandardMetaClass");
     private boolean fastPathBlocked;
 
     public OptimizingStatementWriter(final WriterController controller) {
         super(controller);
     }
 
-    private FastPathData writeGuards(final StatementMeta meta, final Statement statement)
{
+    private FastPathData writeGuards(final StatementMeta meta, final ASTNode node) {
         if (fastPathBlocked || controller.isFastPath() || meta == null || !meta.optimize)
return null;
 
-        controller.getAcg().onLineNumber(statement, null);
+        controller.getAcg().onLineNumber(node, null);
+
         MethodVisitor mv = controller.getMethodVisitor();
         FastPathData fastPathData = new FastPathData();
         Label slowPath = new Label();
@@ -124,10 +126,9 @@ public class OptimizingStatementWriter extends StatementWriter {
         }
 
         // meta class check with boolean holder
-        String owner = BytecodeHelper.getClassInternalName(controller.getClassNode());
         MethodNode mn = controller.getMethodNode();
         if (mn != null) {
-            mv.visitFieldInsn(GETSTATIC, owner, Verifier.STATIC_METACLASS_BOOL, "Z");
+            mv.visitFieldInsn(GETSTATIC, controller.getInternalClassName(), Verifier.STATIC_METACLASS_BOOL,
"Z");
             mv.visitJumpInsn(IFNE, slowPath);
         }
 


Mime
View raw message