You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/05/29 04:26:38 UTC
groovy git commit: Trivial refactoring: Use `AtomicInteger` instead
of `synchronized`(closes #733)
Repository: groovy
Updated Branches:
refs/heads/master 07d14aa44 -> b416bee2f
Trivial refactoring: Use `AtomicInteger` instead of `synchronized`(closes #733)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b416bee2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b416bee2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b416bee2
Branch: refs/heads/master
Commit: b416bee2f0938884cad4d6e666b3bcd4489b83c2
Parents: 07d14aa
Author: sunlan <su...@apache.org>
Authored: Tue May 29 12:26:27 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue May 29 12:26:27 2018 +0800
----------------------------------------------------------------------
src/main/groovy/groovy/lang/GroovyShell.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/b416bee2/src/main/groovy/groovy/lang/GroovyShell.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/GroovyShell.java b/src/main/groovy/groovy/lang/GroovyShell.java
index f155b30..53bc6e6 100644
--- a/src/main/groovy/groovy/lang/GroovyShell.java
+++ b/src/main/groovy/groovy/lang/GroovyShell.java
@@ -38,6 +38,7 @@ import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
import static org.codehaus.groovy.runtime.InvokerHelper.MAIN_METHOD_NAME;
@@ -54,7 +55,7 @@ public class GroovyShell extends GroovyObjectSupport {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private final Binding context;
- private int counter;
+ private final AtomicInteger counter = new AtomicInteger(0);
private final CompilerConfiguration config;
private GroovyClassLoader loader;
@@ -603,7 +604,7 @@ public class GroovyShell extends GroovyObjectSupport {
return parse(in, generateScriptName());
}
- protected synchronized String generateScriptName() {
- return "Script" + (++counter) + ".groovy";
+ protected String generateScriptName() {
+ return "Script" + counter.incrementAndGet() + ".groovy";
}
}