[groovy] branch master updated (471b295 -> 65b9a1c)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[groovy] branch master updated (471b295 -> 65b9a1c)

Daniel.Sun
This is an automated email from the ASF dual-hosted git repository.

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


    from 471b295  GROOVY-9183: remove unused imports
     new 9d53f2a  Trivial refactoring: extract common variables
     new 65b9a1c  Trivial refactoring: statement lambda can be replaced with expression lambda

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/codehaus/groovy/reflection/CachedClass.java  | 20 ++++++++------------
 .../groovy/runtime/DefaultGroovyMethods.java         |  6 ++++--
 2 files changed, 12 insertions(+), 14 deletions(-)

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

[groovy] 01/02: Trivial refactoring: extract common variables

Daniel.Sun
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

commit 9d53f2a019275e5c34e0aa90ef7f680ab2429e3c
Author: Daniel Sun <[hidden email]>
AuthorDate: Mon Dec 2 17:41:51 2019 +0800

    Trivial refactoring: extract common variables
---
 src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 747570a..ea986f4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -16620,10 +16620,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.6.0
      */
     public static float trunc(Float number, int precision) {
+        final double p = Math.pow(10, precision);
+        final double n = number.doubleValue() * p;
         if (number < 0f) {
-            return (float)(Math.ceil(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
+            return (float) (Math.ceil(n) / p);
         }
-        return (float)(Math.floor(number.doubleValue()*Math.pow(10,precision))/Math.pow(10,precision));
+        return (float) (Math.floor(n) / p);
     }
 
     /**

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun
Reply | Threaded
Open this post in threaded view
|

[groovy] 02/02: Trivial refactoring: statement lambda can be replaced with expression lambda

Daniel.Sun
In reply to this post by Daniel.Sun
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

commit 65b9a1c8342e6c30eef7f1da8c6f99785eb4935b
Author: Daniel Sun <[hidden email]>
AuthorDate: Mon Dec 2 17:48:59 2019 +0800

    Trivial refactoring: statement lambda can be replaced with expression lambda
---
 .../org/codehaus/groovy/reflection/CachedClass.java  | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
index 79a7756..04a3347 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
@@ -56,11 +56,9 @@ public class CachedClass {
 
         @Override
         public CachedField[] initValue() {
-            PrivilegedAction<CachedField[]> action = () -> {
-                return Arrays.stream(getTheClass().getDeclaredFields())
-                    .filter(f -> checkCanSetAccessible(f, CachedClass.class))
-                    .map(CachedField::new).toArray(CachedField[]::new);
-            };
+            PrivilegedAction<CachedField[]> action = () -> Arrays.stream(getTheClass().getDeclaredFields())
+                .filter(f -> checkCanSetAccessible(f, CachedClass.class))
+                .map(CachedField::new).toArray(CachedField[]::new);
             return AccessController.doPrivileged(action);
         }
     };
@@ -70,13 +68,11 @@ public class CachedClass {
 
         @Override
         public CachedConstructor[] initValue() {
-            PrivilegedAction<CachedConstructor[]> action = () -> {
-                return Arrays.stream(getTheClass().getDeclaredConstructors())
-                    .filter(c -> !c.isSynthetic()) // GROOVY-9245: exclude inner class ctors
-                    .filter(c -> checkCanSetAccessible(c, CachedClass.class))
-                    .map(c -> new CachedConstructor(CachedClass.this, c))
-                    .toArray(CachedConstructor[]::new);
-            };
+            PrivilegedAction<CachedConstructor[]> action = () -> Arrays.stream(getTheClass().getDeclaredConstructors())
+                .filter(c -> !c.isSynthetic()) // GROOVY-9245: exclude inner class ctors
+                .filter(c -> checkCanSetAccessible(c, CachedClass.class))
+                .map(c -> new CachedConstructor(CachedClass.this, c))
+                .toArray(CachedConstructor[]::new);
             return AccessController.doPrivileged(action);
         }
     };

Apache Groovy committer & PMC member

Blog: http://blog.sunlan.me
Twitter: @daniel_sun