groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Avoid inefficient use of keySet iterator instead of entrySet iterator
Date Fri, 25 May 2018 06:15:11 GMT
Repository: groovy
Updated Branches:
  refs/heads/master ed71b35e7 -> 9fec034e5


 Avoid inefficient use of keySet iterator instead of entrySet iterator


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

Branch: refs/heads/master
Commit: 9fec034e5e81a5411502665872861ba2128e0a4a
Parents: ed71b35
Author: sunlan <sunlan@apache.org>
Authored: Fri May 25 14:08:03 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri May 25 14:14:33 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/ui/GroovyMain.java       |  4 ++--
 .../groovy/runtime/DefaultGroovyMethods.java    | 22 ++++++++++++++------
 2 files changed, 18 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9fec034e/src/main/groovy/groovy/ui/GroovyMain.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/ui/GroovyMain.java b/src/main/groovy/groovy/ui/GroovyMain.java
index 58c6635..8490e15 100644
--- a/src/main/groovy/groovy/ui/GroovyMain.java
+++ b/src/main/groovy/groovy/ui/GroovyMain.java
@@ -230,8 +230,8 @@ public class GroovyMain {
          * @throws ParameterException if the user input was invalid
          */
         boolean process(CommandLine parser) throws ParameterException, IOException {
-            for (String key : systemProperties.keySet()) {
-                System.setProperty(key, systemProperties.get(key));
+            for (Map.Entry<String, String> entry : systemProperties.entrySet()) {
+                System.setProperty(entry.getKey(), entry.getValue());
             }
             GroovyMain main = new GroovyMain();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9fec034e/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 86e2085..1429102 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -10293,8 +10293,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
             return createSimilarMap(self);
         }
         Map<K, V> ret = createSimilarMap(self);
-        for (K key : self.keySet()) {
-            ret.put(key, self.get(key));
+        for (Map.Entry<K, V> entry : self.entrySet()) {
+            K key = entry.getKey();
+            V value = entry.getValue();
+
+            ret.put(key, value);
             if (--num <= 0) {
                 break;
             }
@@ -10588,9 +10591,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
             return cloneSimilarMap(self);
         }
         Map<K, V> ret = createSimilarMap(self);
-        for (K key : self.keySet()) {
+        for (Map.Entry<K, V> entry : self.entrySet()) {
+            K key = entry.getKey();
+            V value = entry.getValue();
+
             if (num-- <= 0) {
-                ret.put(key, self.get(key));
+                ret.put(key, value);
             }
         }
         return ret;
@@ -12744,8 +12750,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
         if (!self.keySet().equals(other.keySet())) {
             return false;
         }
-        for (Object key : self.keySet()) {
-            if (!coercedEquals(self.get(key), other.get(key))) {
+        for (Object o : self.entrySet()) {
+            Map.Entry entry = (Map.Entry) o;
+            Object key = entry.getKey();
+            Object value = entry.getValue();
+
+            if (!coercedEquals(value, other.get(key))) {
                 return false;
             }
         }


Mime
View raw message