You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/01/05 02:39:40 UTC
[groovy] branch master updated: simplify optimizations configuration
This is an automated email from the ASF dual-hosted git repository.
emilles 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 387f505 simplify optimizations configuration
387f505 is described below
commit 387f50532aaf4e85b5bea629925cc069de17d1a9
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Jan 4 20:39:28 2021 -0600
simplify optimizations configuration
---
.../codehaus/groovy/control/CompilationUnit.java | 24 +++------------
.../groovy/control/CompilerConfiguration.java | 36 ++++++++--------------
2 files changed, 17 insertions(+), 43 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
index fdfce7f..a903d34 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilationUnit.java
@@ -74,7 +74,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
-import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
@@ -622,14 +621,14 @@ public class CompilationUnit extends ProcessingUnit {
throughPhase = Math.min(throughPhase, Phases.ALL);
while (throughPhase >= phase && phase <= Phases.ALL) {
-
if (phase == Phases.SEMANTIC_ANALYSIS) {
resolve.doPhaseOperation(this);
if (dequeued()) continue;
- }
-
- if (phase == Phases.CONVERSION) {
- buildASTs();
+ } else if (phase == Phases.CONVERSION) {
+ Collection<SourceUnit> sourceUnits = sources.values();
+ (sourceUnits.size() > 1 && Boolean.TRUE.equals(configuration.getOptimizationOptions().get(CompilerConfiguration.PARALLEL_PARSE))
+ ? sourceUnits.parallelStream() : sourceUnits.stream()
+ ).forEach(SourceUnit::buildAST);
}
processPhaseOperations(phase);
@@ -653,19 +652,6 @@ public class CompilationUnit extends ProcessingUnit {
getErrorCollector().failIfErrors();
}
- private void buildASTs() {
- Boolean bpe = configuration.getOptimizationOptions().get(CompilerConfiguration.PARALLEL_PARSE);
- boolean parallelParseEnabled = null != bpe && bpe;
-
- Collection<SourceUnit> sourceUnits = sources.values();
- Stream<SourceUnit> sourceUnitStream =
- (!parallelParseEnabled || sourceUnits.size() < 2)
- ? sourceUnits.stream() // no need to build AST with parallel stream when we just have one/no source unit
- : sourceUnits.parallelStream();
-
- sourceUnitStream.forEach(SourceUnit::buildAST);
- }
-
private void processPhaseOperations(final int phase) {
for (PhaseOperation op : phaseOperations[phase]) {
op.doPhaseOperation(this);
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index dab2d6b..ad961ca 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -129,8 +129,8 @@ public class CompilerConfiguration {
public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new String[JDK_TO_BYTECODE_VERSION_MAP.size()]);
/**
- * The ASM api version to use when loading/parsing classes, and generating proxy adapter classes.
- */
+ * The ASM API version used when loading/parsing classes and generating proxy adapter classes.
+ */
public static final int ASM_API_VERSION = Opcodes.ASM8;
/**
@@ -442,25 +442,13 @@ public class CompilerConfiguration {
defaultScriptExtension = getSystemPropertySafe("groovy.default.scriptExtension", ".groovy");
optimizationOptions = new HashMap<>(4);
- handleOptimizationOption(optimizationOptions, INVOKEDYNAMIC, "groovy.target.indy", "true");
- handleOptimizationOption(optimizationOptions, GROOVYDOC, "groovy.attach.groovydoc");
- handleOptimizationOption(optimizationOptions, RUNTIME_GROOVYDOC, "groovy.attach.runtime.groovydoc");
- handleOptimizationOption(optimizationOptions, PARALLEL_PARSE, "groovy.parallel.parse", "true");
- }
-
- private void handleOptimizationOption(final Map<String, Boolean> options, final String optionName, final String sysOptionName) {
- handleOptimizationOption(options, optionName, sysOptionName, null);
- }
-
- private void handleOptimizationOption(final Map<String, Boolean> options, final String optionName, final String sysOptionName, String def) {
- String propValue = getSystemPropertySafe(sysOptionName, def);
- boolean optionEnabled = propValue == null
- ? (DEFAULT != null && Boolean.TRUE.equals(DEFAULT.getOptimizationOptions().get(optionName)))
- : Boolean.parseBoolean(propValue);
-
- if (optionEnabled) {
- options.put(optionName, Boolean.TRUE);
- }
+ java.util.function.BiConsumer<String, String> mapper = (key, val) -> {
+ if (val != null) optimizationOptions.put(key, Boolean.valueOf(val));
+ };
+ mapper.accept(INVOKEDYNAMIC, getSystemPropertySafe("groovy.target.indy", "true"));
+ mapper.accept(GROOVYDOC, getSystemPropertySafe("groovy.attach.groovydoc"));
+ mapper.accept(RUNTIME_GROOVYDOC, getSystemPropertySafe("groovy.attach.runtime.groovydoc"));
+ mapper.accept(PARALLEL_PARSE, getSystemPropertySafe("groovy.parallel.parse", "true"));
}
/**
@@ -1075,7 +1063,7 @@ public class CompilerConfiguration {
*/
public boolean isIndyEnabled() {
Boolean indyEnabled = getOptimizationOptions().get(INVOKEDYNAMIC);
- return indyEnabled != Boolean.FALSE;
+ return Optional.ofNullable(indyEnabled).orElse(Boolean.TRUE).booleanValue();
}
/**
@@ -1083,7 +1071,7 @@ public class CompilerConfiguration {
*/
public boolean isGroovydocEnabled() {
Boolean groovydocEnabled = getOptimizationOptions().get(GROOVYDOC);
- return Optional.ofNullable(groovydocEnabled).orElse(Boolean.FALSE);
+ return Optional.ofNullable(groovydocEnabled).orElse(Boolean.FALSE).booleanValue();
}
/**
@@ -1091,6 +1079,6 @@ public class CompilerConfiguration {
*/
public boolean isRuntimeGroovydocEnabled() {
Boolean runtimeGroovydocEnabled = getOptimizationOptions().get(RUNTIME_GROOVYDOC);
- return Optional.ofNullable(runtimeGroovydocEnabled).orElse(Boolean.FALSE);
+ return Optional.ofNullable(runtimeGroovydocEnabled).orElse(Boolean.FALSE).booleanValue();
}
}