groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Minor refactoring
Date Tue, 21 Nov 2017 11:31:21 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X f286bd2e9 -> 62fe0abc2


Minor refactoring

(cherry picked from commit c0da4d8)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/62fe0abc
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/62fe0abc
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/62fe0abc

Branch: refs/heads/GROOVY_2_4_X
Commit: 62fe0abc2d0268742ecf057e04d2a1eef4809c88
Parents: f286bd2
Author: sunlan <sunlan@apache.org>
Authored: Tue Nov 21 19:20:46 2017 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Nov 21 19:31:04 2017 +0800

----------------------------------------------------------------------
 .../BinaryExpressionMultiTypeDispatcher.java    |  3 +--
 .../groovy/classgen/asm/InvocationWriter.java   |  4 ++--
 .../classgen/asm/OptimizingStatementWriter.java | 22 +++++++++-----------
 .../classgen/asm/StatementMetaTypeChooser.java  |  2 +-
 .../groovy/classgen/asm/StatementWriter.java    |  2 +-
 .../classgen/asm/sc/StaticInvocationWriter.java |  4 ++--
 ...ypesBinaryExpressionMultiTypeDispatcher.java |  2 +-
 .../asm/sc/StaticTypesCallSiteWriter.java       |  6 +++---
 .../classgen/asm/sc/StaticTypesTypeChooser.java |  4 ++--
 9 files changed, 23 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
b/src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
index 0427493..2760dff 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/BinaryExpressionMultiTypeDispatcher.java
@@ -245,8 +245,7 @@ public class BinaryExpressionMultiTypeDispatcher extends BinaryExpressionHelper
         Expression leftExpression = binExp.getLeftExpression();
         if (!(leftExpression instanceof BinaryExpression)) return false;
         BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
-        if (leftBinExpr.getOperation().getType() != LEFT_SQUARE_BRACKET) return false;
-        return true;
+        return leftBinExpr.getOperation().getType() == LEFT_SQUARE_BRACKET;
     }
 
     private boolean doAssignmentToArray(BinaryExpression binExp) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
index b902891..5b1193c 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/InvocationWriter.java
@@ -275,7 +275,7 @@ public class InvocationWriter {
                 }
 
                 StatementMeta meta = null;
-                if (origin!=null) meta = (StatementMeta) origin.getNodeMetaData(StatementMeta.class);
+                if (origin!=null) meta = origin.getNodeMetaData(StatementMeta.class);
                 MethodNode mn = null;
                 if (meta!=null) mn = meta.target;
 
@@ -523,7 +523,7 @@ public class InvocationWriter {
     private boolean writeDirectConstructorCall(ConstructorCallExpression call) {
         if (!controller.isFastPath()) return false;
         
-        StatementMeta meta = (StatementMeta) call.getNodeMetaData(StatementMeta.class);
+        StatementMeta meta = call.getNodeMetaData(StatementMeta.class);
         ConstructorNode cn = null;
         if (meta!=null) cn = (ConstructorNode) meta.target;
         if (cn==null) return false;

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
index 19bb3f5..123d2f4 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/OptimizingStatementWriter.java
@@ -148,7 +148,7 @@ public class OptimizingStatementWriter extends StatementWriter {
 
     @Override
     public void writeBlockStatement(BlockStatement statement) {
-        StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+        StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
         FastPathData fastPathData = writeGuards(meta, statement);
 
         if (fastPathData==null) {
@@ -175,7 +175,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeDoWhileLoop(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             FastPathData fastPathData = writeGuards(meta, statement);
 
             boolean oldFastPathBlock = fastPathBlocked;
@@ -213,7 +213,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeForInLoop(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             FastPathData fastPathData = writeGuards(meta, statement);
 
             boolean oldFastPathBlock = fastPathBlocked;
@@ -233,7 +233,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeForLoopWithClosureList(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             FastPathData fastPathData = writeGuards(meta, statement);
 
             boolean oldFastPathBlock = fastPathBlocked;
@@ -253,7 +253,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeWhileLoop(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             FastPathData fastPathData = writeGuards(meta, statement);
 
             boolean oldFastPathBlock = fastPathBlocked;
@@ -294,8 +294,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         // fastPathBlocked -> slow path
         if (fastPathBlocked) return false;
         // controller.isFastPath() -> fastPath
-        if (controller.isFastPath()) return false;
-        return true;
+        return !controller.isFastPath();
     }
 
     @Override
@@ -303,7 +302,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeReturn(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             if (isNewPathFork(meta) && writeDeclarationExtraction(statement)) {
                 if (meta.declaredVariableExpression != null) {
                     // declaration was replaced by assignment so we need to define the variable
@@ -331,7 +330,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         if (controller.isFastPath()) {
             super.writeExpressionStatement(statement);
         } else {
-            StatementMeta meta = (StatementMeta) statement.getNodeMetaData(StatementMeta.class);
+            StatementMeta meta = statement.getNodeMetaData(StatementMeta.class);
             // we have to have handle DelcarationExpressions special, since their 
             // entry should be outside the optimization path, we have to do that of
             // course only if we are actually going to do two different paths, 
@@ -417,7 +416,7 @@ public class OptimizingStatementWriter extends StatementWriter {
     }
 
     private static StatementMeta addMeta(ASTNode node) {
-        StatementMeta metaOld = (StatementMeta) node.getNodeMetaData(StatementMeta.class);
+        StatementMeta metaOld = node.getNodeMetaData(StatementMeta.class);
         StatementMeta meta = metaOld;
         if (meta==null) meta = new StatementMeta();
         meta.optimize = true;
@@ -882,8 +881,7 @@ public class OptimizingStatementWriter extends StatementWriter {
         private static boolean validTypeForCall(ClassNode type) {
             // do call only for final classes and primitive types
             if (isPrimitiveType(type)) return true;
-            if ((type.getModifiers() & ACC_FINAL)>0) return true;
-            return false;
+            return (type.getModifiers() & ACC_FINAL) > 0;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/StatementMetaTypeChooser.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/StatementMetaTypeChooser.java b/src/main/org/codehaus/groovy/classgen/asm/StatementMetaTypeChooser.java
index 586a183..2ada09d 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/StatementMetaTypeChooser.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/StatementMetaTypeChooser.java
@@ -35,7 +35,7 @@ import org.codehaus.groovy.ast.expr.VariableExpression;
 public class StatementMetaTypeChooser implements TypeChooser {
     public ClassNode resolveType(final Expression exp, final ClassNode current) {
         if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
-        OptimizingStatementWriter.StatementMeta meta = (OptimizingStatementWriter.StatementMeta)
exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
+        OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
         ClassNode type = null;
         if (meta != null) type = meta.type;
         if (type != null) return type;

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java b/src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
index 471ace4..89dc588 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/StatementWriter.java
@@ -178,7 +178,7 @@ public class StatementWriter {
         mv.visitLabel(cond);
         // visit condition leave boolean on stack
         {
-            Expression condExpr = (Expression) expressions.get(condIndex);
+            Expression condExpr = expressions.get(condIndex);
             int mark = controller.getOperandStack().getStackLength();
             condExpr.visit(controller.getAcg());
             controller.getOperandStack().castToBool(mark,true);

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
index 5207235..f8d895b 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java
@@ -383,11 +383,11 @@ public class StaticInvocationWriter extends InvocationWriter {
                 Parameter curParam = para[i];
                 ClassNode curParamType = curParam.getType();
                 Expression curArg = j < argumentList.size() ? argumentList.get(j) : null;
-                Expression initialExpression = (Expression) curParam.getNodeMetaData(StaticTypesMarker.INITIAL_EXPRESSION);
+                Expression initialExpression = curParam.getNodeMetaData(StaticTypesMarker.INITIAL_EXPRESSION);
                 if (initialExpression == null && curParam.hasInitialExpression())
                     initialExpression = curParam.getInitialExpression();
                 if (initialExpression == null && curParam.getNodeMetaData(Verifier.INITIAL_EXPRESSION)!=null)
{
-                    initialExpression = (Expression) curParam.getNodeMetaData(Verifier.INITIAL_EXPRESSION);
+                    initialExpression = curParam.getNodeMetaData(Verifier.INITIAL_EXPRESSION);
                 }
                 ClassNode curArgType = curArg == null ? null : typeChooser.resolveType(curArg,
classNode);
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
index 9441007..129e1dd 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesBinaryExpressionMultiTypeDispatcher.java
@@ -329,7 +329,7 @@ public class StaticTypesBinaryExpressionMultiTypeDispatcher extends BinaryExpres
         if (field != null && Modifier.isPrivate(field.getModifiers())
             && (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType,
classNode) || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode,receiverType))
             && !receiverType.equals(classNode)) {
-            Map<String, MethodNode> mutators = (Map<String, MethodNode>) receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_MUTATORS);
+            Map<String, MethodNode> mutators = receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_MUTATORS);
             if (mutators != null) {
                 MethodNode methodNode = mutators.get(fieldName);
                 if (methodNode != null) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 43bd529..32c48c0 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -270,7 +270,7 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements
Opcodes
     }
 
     private void writeListDotProperty(final Expression receiver, final String methodName,
final MethodVisitor mv, final boolean safe) {
-        ClassNode componentType = (ClassNode) receiver.getNodeMetaData(StaticCompilationMetadataKeys.COMPONENT_TYPE);
+        ClassNode componentType = receiver.getNodeMetaData(StaticCompilationMetadataKeys.COMPONENT_TYPE);
         if (componentType==null) {
             componentType = OBJECT_TYPE;
         }
@@ -386,7 +386,7 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements
Opcodes
         if (field!=null && Modifier.isPrivate(field.getModifiers())
                 && (StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(receiverType,
classNode) || StaticInvocationWriter.isPrivateBridgeMethodsCallAllowed(classNode,receiverType))
                 && !receiverType.equals(classNode)) {
-            Map<String, MethodNode> accessors = (Map<String, MethodNode>) receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_ACCESSORS);
+            Map<String, MethodNode> accessors = receiverType.redirect().getNodeMetaData(StaticCompilationMetadataKeys.PRIVATE_FIELDS_ACCESSORS);
             if (accessors!=null) {
                 MethodNode methodNode = accessors.get(fieldName);
                 if (methodNode!=null) {
@@ -417,7 +417,7 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements
Opcodes
             if (controller.getInvocationWriter() instanceof StaticInvocationWriter) {
                 MethodCallExpression currentCall = ((StaticInvocationWriter) controller.getInvocationWriter()).getCurrentCall();
                 if (currentCall != null && currentCall.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER)
!= null) {
-                    property = (String) currentCall.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
+                    property = currentCall.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
                     String[] props = property.split("\\.");
                     BytecodeExpression thisLoader = new BytecodeExpression() {
                         @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/62fe0abc/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
index b54c988..a3e4551 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesTypeChooser.java
@@ -37,9 +37,9 @@ public class StaticTypesTypeChooser extends StatementMetaTypeChooser {
     @Override
     public ClassNode resolveType(final Expression exp, final ClassNode current) {
         ASTNode target = exp instanceof VariableExpression ? getTarget((VariableExpression)
exp) : exp;
-        ClassNode inferredType = (ClassNode) target.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE);
+        ClassNode inferredType = target.getNodeMetaData(StaticTypesMarker.DECLARATION_INFERRED_TYPE);
         if (inferredType == null) {
-            inferredType = (ClassNode) target.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
+            inferredType = target.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
             if (inferredType == null && target instanceof VariableExpression &&
((VariableExpression) target).getAccessedVariable() instanceof Parameter) {
                 target = (Parameter) ((VariableExpression) target).getAccessedVariable();
                 inferredType = ((Parameter) target).getOriginType();


Mime
View raw message