groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] branch master updated: Tweak GROOVY-9126: Remove unnecessary checks (#1096)
Date Thu, 21 Nov 2019 23:42:08 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan 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 d787ddd  Tweak GROOVY-9126: Remove unnecessary checks (#1096)
d787ddd is described below

commit d787ddd244a8e8c805d4941366faa1aa3f369c2c
Author: Daniel.Sun <sunlan@apache.org>
AuthorDate: Fri Nov 22 07:41:59 2019 +0800

    Tweak GROOVY-9126: Remove unnecessary checks (#1096)
    
    * Tweak GROOVY-9126: Remove unnecessary checks
    
    * Check if block is empty
---
 .../java/org/codehaus/groovy/classgen/asm/StatementWriter.java    | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
index 8459b89..ebe0428 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/StatementWriter.java
@@ -97,7 +97,7 @@ public class StatementWriter {
 
         // GROOVY-7647
         if (block.getLastLineNumber() > 0
-                && !methodOrConstructorsLastReturnStatementExists(block) // GROOVY-9126
+                && !isMethodOrConstructorNonEmptyBlock(block) // GROOVY-9126
         ) {
             MethodVisitor mv = controller.getMethodVisitor();
             Label blockEnd = new Label();
@@ -108,7 +108,7 @@ public class StatementWriter {
         controller.getOperandStack().popDownTo(mark);
     }
 
-    private boolean methodOrConstructorsLastReturnStatementExists(BlockStatement block) {
+    private boolean isMethodOrConstructorNonEmptyBlock(BlockStatement block) {
         MethodNode methodNode = controller.getMethodNode();
         if (null == methodNode) {
             methodNode = controller.getConstructorNode();
@@ -118,9 +118,7 @@ public class StatementWriter {
             return false;
         }
 
-        List<Statement> statementList = block.getStatements();
-        final int size = statementList.size();
-        return size > 0 && statementList.get(size - 1) instanceof ReturnStatement;
+        return !block.getStatements().isEmpty();
     }
 
     public void writeForStatement(ForStatement loop) {


Mime
View raw message