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 2020/01/17 01:03:40 UTC
[groovy] branch GROOVY_3_0_X updated (20e6b4b -> 6645f62)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 20e6b4b Revert removing `Comparable` for `NumberRange`
new 55efc6c use consistent class loader for finding DGMs
new 97b92d7 Use String#replace instead of String#replaceAll where possible for improved performance.
new 9ec70f2 Use System#lineSeparator instead of System.getProperty("line.separator") (closes #1145)
new 6645f62 Use StringBuilder#append(char[] str, int offset, int len) to improve performance.
The 4 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:
.../groovy/antlr/treewalker/MindMapPrinter.java | 6 ++---
.../java/org/codehaus/groovy/ast/GenericsType.java | 2 +-
.../org/codehaus/groovy/classgen/Verifier.java | 2 +-
.../classgen/asm/sc/StaticTypesCallSiteWriter.java | 4 ++--
...StaticTypesMethodReferenceExpressionWriter.java | 5 ++--
.../org/codehaus/groovy/runtime/InvokerHelper.java | 8 +++----
.../codehaus/groovy/tools/LoaderConfiguration.java | 4 ++--
.../java/org/codehaus/groovy/tools/Utilities.java | 2 +-
.../transform/stc/StaticTypeCheckingVisitor.java | 28 ++++++++++------------
.../tck/ClassicGroovyTestGeneratorHelper.java | 2 +-
.../org/codehaus/groovy/tck/TestGenerator.groovy | 2 +-
src/test/groovy/PrintTest.groovy | 2 +-
src/test/groovy/inspect/InspectorTest.java | 2 +-
src/test/groovy/io/PlatformLineWriterTest.java | 2 +-
.../main/java/org/codehaus/groovy/ant/Groovyc.java | 2 +-
.../console/ui/AstNodeToScriptAdapter.groovy | 2 +-
.../main/groovy/groovy/console/ui/Console.groovy | 12 +++++-----
.../console/ui/text/SmartDocumentFilter.java | 2 +-
.../ui/text/StructuredSyntaxDocumentFilter.java | 2 +-
.../apache/groovy/groovysh/CommandSupport.groovy | 2 +-
.../org/apache/groovy/groovysh/Parser.groovy | 2 +-
.../groovy/groovysh/commands/DocCommand.groovy | 4 ++--
.../groovy/groovysh/commands/ImportCommand.groovy | 2 +-
.../main/java/groovy/sql/ExtractIndexAndSql.java | 2 +-
.../main/groovy/groovy/swing/SwingBuilder.groovy | 2 +-
.../groovy/swing/factory/ActionFactory.groovy | 2 +-
.../groovy/text/markup/TemplateConfiguration.java | 2 +-
.../java/groovy/text/XmlTemplateEngineTest.java | 6 ++---
.../groovy/parser/antlr4/util/StringUtils.java | 2 +-
29 files changed, 57 insertions(+), 60 deletions(-)
[groovy] 01/04: use consistent class loader for finding DGMs
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 55efc6cd50140831da06cc5db10f13c3d4613780
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Jan 16 16:24:10 2020 -0600
use consistent class loader for finding DGMs
(cherry picked from commit 692e42f4be1846d36fbec7203c0764c2cc2a008c)
---
.../classgen/asm/sc/StaticTypesCallSiteWriter.java | 4 ++--
...StaticTypesMethodReferenceExpressionWriter.java | 5 ++--
.../transform/stc/StaticTypeCheckingVisitor.java | 28 ++++++++++------------
3 files changed, 17 insertions(+), 20 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 973408b..4b5827c 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -739,11 +739,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
boolean acceptAnyMethod =
MAP_TYPE.equals(rType) || rType.implementsInterface(MAP_TYPE)
|| LIST_TYPE.equals(rType) || rType.implementsInterface(LIST_TYPE);
- List<MethodNode> nodes = StaticTypeCheckingSupport.findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), rType, message, args);
+ List<MethodNode> nodes = findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), rType, message, args);
if (nodes.isEmpty()) {
// retry with raw types
rType = rType.getPlainNodeReference();
- nodes = StaticTypeCheckingSupport.findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), rType, message, args);
+ nodes = findDGMMethodsByNameAndArguments(controller.getSourceUnit().getClassLoader(), rType, message, args);
}
nodes = StaticTypeCheckingSupport.chooseBestMethod(rType, nodes, args);
if (nodes.size() == 1 || (nodes.size() > 1 && acceptAnyMethod)) {
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
index c12a556..28a764c 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
@@ -39,10 +39,8 @@ import org.codehaus.groovy.classgen.asm.BytecodeHelper;
import org.codehaus.groovy.classgen.asm.MethodReferenceExpressionWriter;
import org.codehaus.groovy.classgen.asm.WriterController;
import org.codehaus.groovy.runtime.ArrayTypeUtils;
-import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
import org.codehaus.groovy.syntax.RuntimeParserException;
import org.codehaus.groovy.transform.stc.ExtensionMethodNode;
-import org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@@ -58,6 +56,7 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.filterMethodsByVisibility;
+import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsForClassNode;
import static org.codehaus.groovy.transform.stc.StaticTypesMarker.CLOSURE_ARGUMENTS;
/**
@@ -299,7 +298,7 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
private MethodNode findMethodRefMethod(String methodRefName, Parameter[] abstractMethodParameters, Expression typeOrTargetRef) {
ClassNode typeOrTargetRefType = typeOrTargetRef.getType();
List<MethodNode> methodNodeList = typeOrTargetRefType.getMethods(methodRefName);
- Set<MethodNode> dgmMethodNodeSet = StaticTypeCheckingSupport.findDGMMethodsForClassNode(MetaClassRegistryImpl.class.getClassLoader(), typeOrTargetRefType, methodRefName);
+ Set<MethodNode> dgmMethodNodeSet = findDGMMethodsForClassNode(controller.getSourceUnit().getClassLoader(), typeOrTargetRefType, methodRefName);
List<MethodNode> allMethodNodeList = new LinkedList<>(methodNodeList);
allMethodNodeList.addAll(dgmMethodNodeSet);
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 1b06c8c..8ecbd51 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -244,6 +244,7 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.choose
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.evaluateExpression;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.extractGenericsConnections;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.extractGenericsParameterMapOfThis;
+import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.filterMethodsByVisibility;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findDGMMethodsByNameAndArguments;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findSetters;
import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.findTargetVariable;
@@ -1587,8 +1588,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (isPrimitiveType(testClass))
dgmReceivers.add(getWrapper(testClass));
for (ClassNode dgmReceiver : dgmReceivers) {
- List<MethodNode> methods = findDGMMethodsByNameAndArguments(getTransformLoader(), dgmReceiver, "get" + capName, ClassNode.EMPTY_ARRAY);
- for (MethodNode method : findDGMMethodsByNameAndArguments(getTransformLoader(), dgmReceiver, "is" + capName, ClassNode.EMPTY_ARRAY)) {
+ List<MethodNode> methods = findDGMMethodsByNameAndArguments(getSourceUnit().getClassLoader(), dgmReceiver, "get" + capName, ClassNode.EMPTY_ARRAY);
+ for (MethodNode method : findDGMMethodsByNameAndArguments(getSourceUnit().getClassLoader(), dgmReceiver, "is" + capName, ClassNode.EMPTY_ARRAY)) {
if (Boolean_TYPE.equals(getWrapper(method.getReturnType()))) methods.add(method);
}
if (!methods.isEmpty()) {
@@ -2874,8 +2875,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
ClosureSignatureHint hintInstance = hint.getDeclaredConstructor().newInstance();
closureSignatures = hintInstance.getClosureSignatures(
selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode() : selectedMethod,
- typeCheckingContext.source,
- typeCheckingContext.compilationUnit,
+ typeCheckingContext.getSource(),
+ typeCheckingContext.getCompilationUnit(),
convertToStringArray(options), expression);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
throw new GroovyBugError(e);
@@ -2896,8 +2897,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
arguments,
expression,
selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode() : selectedMethod,
- typeCheckingContext.source,
- typeCheckingContext.compilationUnit,
+ typeCheckingContext.getSource(),
+ typeCheckingContext.getCompilationUnit(),
convertToStringArray(options));
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
throw new GroovyBugError(e);
@@ -2905,8 +2906,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
private ClassLoader getTransformLoader() {
- CompilationUnit compilationUnit = typeCheckingContext.getCompilationUnit();
- return compilationUnit != null ? compilationUnit.getTransformLoader() : getSourceUnit().getClassLoader();
+ return Optional.ofNullable(typeCheckingContext.getCompilationUnit()).map(CompilationUnit::getTransformLoader).orElseGet(() -> getSourceUnit().getClassLoader());
}
private void doInferClosureParameterTypes(final ClassNode receiver, final Expression arguments, final ClosureExpression expression, final MethodNode selectedMethod, final Expression hintClass, final Expression resolverClass, final Expression options) {
@@ -4665,9 +4665,11 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
collectAllInterfaceMethodsByName(receiver, name, methods);
}
- // lookup in DGM methods too
- findDGMMethodsByNameAndArguments(getTransformLoader(), receiver, name, args, methods);
- methods = filterMethodsByVisibility(methods);
+ if (!"<init>".equals(name) && !"<clinit>".equals(name)) {
+ // lookup in DGM methods too
+ findDGMMethodsByNameAndArguments(getSourceUnit().getClassLoader(), receiver, name, args, methods);
+ }
+ methods = filterMethodsByVisibility(methods, typeCheckingContext.getEnclosingClassNode());
List<MethodNode> chosen = chooseBestMethod(receiver, methods, args);
if (!chosen.isEmpty()) return chosen;
@@ -4694,10 +4696,6 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
return EMPTY_METHODNODE_LIST;
}
- private List<MethodNode> filterMethodsByVisibility(final List<MethodNode> methodNodeList) {
- return StaticTypeCheckingSupport.filterMethodsByVisibility(methodNodeList, typeCheckingContext.getEnclosingClassNode());
- }
-
/**
* Given a method name and a prefix, returns the name of the property that should be looked up,
* following the java beans rules. For example, "getName" would return "name", while
[groovy] 03/04: Use System#lineSeparator instead of
System.getProperty("line.separator") (closes #1145)
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 9ec70f25ac43e4ed588750f112eced9ad06dbdbb
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Fri Jan 17 08:37:01 2020 +0800
Use System#lineSeparator instead of System.getProperty("line.separator") (closes #1145)
(cherry picked from commit d258408d7eda093c20d20dcf2de817e34a17e952)
---
src/main/java/org/codehaus/groovy/tools/Utilities.java | 2 +-
.../org/codehaus/groovy/tck/ClassicGroovyTestGeneratorHelper.java | 2 +-
src/tck/src/org/codehaus/groovy/tck/TestGenerator.groovy | 2 +-
src/test/groovy/PrintTest.groovy | 2 +-
src/test/groovy/inspect/InspectorTest.java | 2 +-
src/test/groovy/io/PlatformLineWriterTest.java | 2 +-
.../groovy-console/src/main/groovy/groovy/console/ui/Console.groovy | 6 +++---
.../main/groovy/org/apache/groovy/groovysh/CommandSupport.groovy | 2 +-
.../src/main/groovy/org/apache/groovy/groovysh/Parser.groovy | 2 +-
.../src/main/groovy/groovy/text/markup/TemplateConfiguration.java | 2 +-
.../src/test/java/groovy/text/XmlTemplateEngineTest.java | 6 +++---
11 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/tools/Utilities.java b/src/main/java/org/codehaus/groovy/tools/Utilities.java
index 522b5d3..41a7b00 100644
--- a/src/main/java/org/codehaus/groovy/tools/Utilities.java
+++ b/src/main/java/org/codehaus/groovy/tools/Utilities.java
@@ -72,6 +72,6 @@ public abstract class Utilities
return true;
}
- private static String eol = System.getProperty( "line.separator", "\n" );
+ private static String eol = System.lineSeparator();
}
diff --git a/src/tck/src/org/codehaus/groovy/tck/ClassicGroovyTestGeneratorHelper.java b/src/tck/src/org/codehaus/groovy/tck/ClassicGroovyTestGeneratorHelper.java
index 373d5ea..a0854c3 100644
--- a/src/tck/src/org/codehaus/groovy/tck/ClassicGroovyTestGeneratorHelper.java
+++ b/src/tck/src/org/codehaus/groovy/tck/ClassicGroovyTestGeneratorHelper.java
@@ -105,5 +105,5 @@ public class ClassicGroovyTestGeneratorHelper implements TestGeneratorHelper {
return decorateWithLineNumbersAndErrorMessage(theSrcText,null);
}
- protected String lineSep = System.getProperty("line.separator");
+ protected String lineSep = System.lineSeparator();
}
diff --git a/src/tck/src/org/codehaus/groovy/tck/TestGenerator.groovy b/src/tck/src/org/codehaus/groovy/tck/TestGenerator.groovy
index aa93eeb..85d32db 100644
--- a/src/tck/src/org/codehaus/groovy/tck/TestGenerator.groovy
+++ b/src/tck/src/org/codehaus/groovy/tck/TestGenerator.groovy
@@ -118,7 +118,7 @@ class TestGenerator{
result.println(" }")
result.println(" }")
}
- result.println(' protected String lineSep = System.getProperty("line.separator");')
+ result.println(' protected String lineSep = System.lineSeparator();')
result.println(' protected TestGeneratorHelper helper = new ClassicGroovyTestGeneratorHelper();')
result.println("}")
diff --git a/src/test/groovy/PrintTest.groovy b/src/test/groovy/PrintTest.groovy
index 53c3656..f567f3f 100644
--- a/src/test/groovy/PrintTest.groovy
+++ b/src/test/groovy/PrintTest.groovy
@@ -96,7 +96,7 @@ class PrintTest extends GroovyTestCase {
}
}
-def NEWLINE = System.getProperty("line.separator")
+def NEWLINE = System.lineSeparator()
void doTest(def param) {
StringWriter sw1 = new StringWriter()
diff --git a/src/test/groovy/inspect/InspectorTest.java b/src/test/groovy/inspect/InspectorTest.java
index 51a3bc8..6284da9 100644
--- a/src/test/groovy/inspect/InspectorTest.java
+++ b/src/test/groovy/inspect/InspectorTest.java
@@ -213,7 +213,7 @@ public class InspectorTest extends MockObjectTestCase implements Serializable {
public void testPrint() {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(bytes);
- String ls = System.getProperty("line.separator");
+ String ls = System.lineSeparator();
String[] first = {"a", "b"};
String[] second = {"x", "y"};
Object[] memberInfo = {first, second};
diff --git a/src/test/groovy/io/PlatformLineWriterTest.java b/src/test/groovy/io/PlatformLineWriterTest.java
index e915e42..395fc5b 100644
--- a/src/test/groovy/io/PlatformLineWriterTest.java
+++ b/src/test/groovy/io/PlatformLineWriterTest.java
@@ -29,7 +29,7 @@ import java.io.Writer;
public class PlatformLineWriterTest extends TestCase {
public void testPlatformLineWriter() throws IOException, ClassNotFoundException {
- String LS = System.getProperty("line.separator");
+ String LS = System.lineSeparator();
Binding binding = new Binding();
binding.setVariable("first", "Tom");
binding.setVariable("last", "Adams");
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index a8046c5..215f0a1 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -1230,7 +1230,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
scriptRunning = true
interruptAction.enabled = true
stackOverFlowError = false // reset this flag before running a script
- def endLine = System.getProperty('line.separator')
+ def endLine = System.lineSeparator()
def record = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
addToHistory(record)
@@ -1306,7 +1306,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
return
}
stackOverFlowError = false // reset this flag before running a script
- def endLine = System.getProperty('line.separator')
+ def endLine = System.lineSeparator()
def record = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
@@ -1361,7 +1361,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
}
private void setInputTextFromHistory(newIndex) {
- def endLine = System.getProperty('line.separator')
+ def endLine = System.lineSeparator()
if (historyIndex >= history.size()) {
pendingRecord = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/CommandSupport.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/CommandSupport.groovy
index bdab2f1..09f4b78 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/CommandSupport.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/CommandSupport.groovy
@@ -33,7 +33,7 @@ import org.codehaus.groovy.tools.shell.util.MessageSource
abstract class CommandSupport
implements Command
{
- protected static final String NEWLINE = System.properties['line.separator']
+ protected static final String NEWLINE = System.lineSeparator()
/** Instance logger for the command, initialized late to include the command name. */
protected final Logger log
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
index b793d60..5e26dd3 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Parser.groovy
@@ -35,7 +35,7 @@ interface Parsing {
* Provides a facade over the parser to recognize valid Groovy syntax.
*/
class Parser {
- static final String NEWLINE = System.getProperty('line.separator')
+ static final String NEWLINE = System.lineSeparator()
private static final Logger log = Logger.create(Parser)
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/TemplateConfiguration.java b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/TemplateConfiguration.java
index 282bdbe..e5ff8dc 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/TemplateConfiguration.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/TemplateConfiguration.java
@@ -28,7 +28,7 @@ public class TemplateConfiguration {
private String declarationEncoding;
private boolean expandEmptyElements;
private boolean useDoubleQuotes;
- private String newLineString = System.getProperty("line.separator");
+ private String newLineString = System.lineSeparator();
private boolean autoEscape = false;
private boolean autoIndent = false;
private String autoIndentString = DelegatingIndentWriter.SPACES;
diff --git a/subprojects/groovy-templates/src/test/java/groovy/text/XmlTemplateEngineTest.java b/subprojects/groovy-templates/src/test/java/groovy/text/XmlTemplateEngineTest.java
index 159cc0e..39eb607 100644
--- a/subprojects/groovy-templates/src/test/java/groovy/text/XmlTemplateEngineTest.java
+++ b/subprojects/groovy-templates/src/test/java/groovy/text/XmlTemplateEngineTest.java
@@ -39,7 +39,7 @@ public class XmlTemplateEngineTest extends TestCase {
String xmlResult = "<xml>\n"
+ " Stein\n"
+ xmlTemplateEngine.getIndentation() + "Stein\n"
- + "Stein" + System.getProperty("line.separator")
+ + "Stein" + System.lineSeparator()
+ "</xml>\n";
Template template = xmlTemplateEngine.createTemplate(xmlScript);
assertEquals(xmlResult, template.make(binding).toString());
@@ -59,7 +59,7 @@ public class XmlTemplateEngineTest extends TestCase {
String xmlResult = "<xml>\n"
+ " Stein Stein\n"
+ xmlTemplateEngine.getIndentation() + "Stein Stein\n"
- + "Stein" + System.getProperty("line.separator")
+ + "Stein" + System.lineSeparator()
+ "</xml>\n";
Template template = xmlTemplateEngine.createTemplate(xmlScript);
assertEquals(xmlResult, template.make(binding).toString());
@@ -80,7 +80,7 @@ public class XmlTemplateEngineTest extends TestCase {
+ " Stein Stein\n"
+ xmlTemplateEngine.getIndentation() + "Stein Stein\n"
+ xmlTemplateEngine.getIndentation() + "<nonamespace>\n"
- + "Stein" + System.getProperty("line.separator")
+ + "Stein" + System.lineSeparator()
+ xmlTemplateEngine.getIndentation() + "</nonamespace>\n"
+ "</foo:bar>\n";
Template template = xmlTemplateEngine.createTemplate(xmlScript);
[groovy] 02/04: Use String#replace instead of String#replaceAll
where possible for improved performance.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 97b92d7224bba89fd0ff0ec3bf4c5cf13c1f81c0
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Thu Jan 16 22:14:17 2020 +0100
Use String#replace instead of String#replaceAll where possible for improved performance.
(cherry picked from commit 7465b2c2878dbab1e7d7a299b024693a701ff27d)
---
.../java/org/codehaus/groovy/antlr/treewalker/MindMapPrinter.java | 6 +++---
src/main/java/org/codehaus/groovy/classgen/Verifier.java | 2 +-
src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java | 8 ++++----
.../main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy | 2 +-
.../src/main/groovy/groovy/console/ui/Console.groovy | 6 +++---
.../main/groovy/groovy/console/ui/text/SmartDocumentFilter.java | 2 +-
.../groovy/console/ui/text/StructuredSyntaxDocumentFilter.java | 2 +-
.../groovy/org/apache/groovy/groovysh/commands/DocCommand.groovy | 4 ++--
.../org/apache/groovy/groovysh/commands/ImportCommand.groovy | 2 +-
.../groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy | 2 +-
10 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/antlr/treewalker/MindMapPrinter.java b/src/main/java/org/codehaus/groovy/antlr/treewalker/MindMapPrinter.java
index d4d9935..9c4735c 100644
--- a/src/main/java/org/codehaus/groovy/antlr/treewalker/MindMapPrinter.java
+++ b/src/main/java/org/codehaus/groovy/antlr/treewalker/MindMapPrinter.java
@@ -368,9 +368,9 @@ public class MindMapPrinter extends VisitorAdapter {
}
name = name.replace('"',' ');
name = name.replace('\'',' ');
- name = name.replaceAll("&","&");
- name = name.replaceAll("<","<");
- name = name.replaceAll(">",">");
+ name = name.replace("&","&");
+ name = name.replace("<","<");
+ name = name.replace(">",">");
name = name.trim();
return name;
}
diff --git a/src/main/java/org/codehaus/groovy/classgen/Verifier.java b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
index 204e443..bc7ad7b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/Verifier.java
+++ b/src/main/java/org/codehaus/groovy/classgen/Verifier.java
@@ -361,7 +361,7 @@ public class Verifier implements GroovyClassVisitor, Opcodes {
if (BytecodeHelper.isClassLiteralPossible(node) || BytecodeHelper.isSameCompilationUnit(classNode, node)) {
BytecodeHelper.visitClassLiteral(mv, node);
} else {
- mv.visitMethodInsn(INVOKESTATIC, classInternalName, "$get$$class$" + classInternalName.replaceAll("/", "\\$"), "()Ljava/lang/Class;", false);
+ mv.visitMethodInsn(INVOKESTATIC, classInternalName, "$get$$class$" + classInternalName.replace('/', '$'), "()Ljava/lang/Class;", false);
}
Label l1 = new Label();
mv.visitJumpInsn(IF_ACMPEQ, l1);
diff --git a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
index 89013bf..ef55fb4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -663,7 +663,7 @@ public class InvokerHelper {
if (arguments instanceof String) {
if (verbose) {
String arg = escapeBackslashes((String) arguments)
- .replaceAll("'", "\\\\'"); // single quotation mark
+ .replace("'", "\\'"); // single quotation mark
return "'" + arg + "'";
} else {
return (String) arguments;
@@ -687,9 +687,9 @@ public class InvokerHelper {
return orig
.replace("\\", "\\\\") // backslash
.replace("\n", "\\n") // line feed
- .replaceAll("\\r", "\\\\r") // carriage return
- .replaceAll("\\t", "\\\\t") // tab
- .replaceAll("\\f", "\\\\f"); // form feed
+ .replace("\r", "\\r") // carriage return
+ .replace("\t", "\\t") // tab
+ .replace("\f", "\\f"); // form feed
}
private static String handleFormattingException(Object item, Exception ex) {
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
index 1edda5f..fa78b38 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstNodeToScriptAdapter.groovy
@@ -516,7 +516,7 @@ class AstNodeToScriptVisitor implements CompilationUnit.IPrimaryClassNodeOperati
// GROOVY-5150: final constants may be initialized directly
print ' = '
if (ClassHelper.STRING_TYPE == type) {
- print "'" + node.initialValueExpression.text.replaceAll("'", "\\\\'") + "'"
+ print "'" + node.initialValueExpression.text.replace("'", "\\'") + "'"
} else if (ClassHelper.char_TYPE == type) {
print "'${node.initialValueExpression.text}'"
} else {
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index 1a658ba..a8046c5 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -1231,7 +1231,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
interruptAction.enabled = true
stackOverFlowError = false // reset this flag before running a script
def endLine = System.getProperty('line.separator')
- def record = new HistoryRecord(allText: inputArea.getText().replaceAll(endLine, '\n'),
+ def record = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
addToHistory(record)
pendingRecord = new HistoryRecord(allText: '', selectionStart: 0, selectionEnd: 0)
@@ -1307,7 +1307,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
}
stackOverFlowError = false // reset this flag before running a script
def endLine = System.getProperty('line.separator')
- def record = new HistoryRecord(allText: inputArea.getText().replaceAll(endLine, '\n'),
+ def record = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
if (prefs.getBoolean('autoClearOutput', false)) clearOutput()
@@ -1363,7 +1363,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
private void setInputTextFromHistory(newIndex) {
def endLine = System.getProperty('line.separator')
if (historyIndex >= history.size()) {
- pendingRecord = new HistoryRecord(allText: inputArea.getText().replaceAll(endLine, '\n'),
+ pendingRecord = new HistoryRecord(allText: inputArea.getText().replace(endLine, '\n'),
selectionStart: textSelectionStart, selectionEnd: textSelectionEnd)
}
historyIndex = newIndex
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
index ed435cf..5e49ca6 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/SmartDocumentFilter.java
@@ -163,7 +163,7 @@ public class SmartDocumentFilter extends DocumentFilter {
private String replaceMetaCharacters(String string) {
// just in case remove carriage returns
- string = string.replaceAll("\\t", TAB_REPLACEMENT);
+ string = string.replace("\\t", TAB_REPLACEMENT);
return string;
}
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/StructuredSyntaxDocumentFilter.java b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/StructuredSyntaxDocumentFilter.java
index 6df8fc1..14d3747 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/StructuredSyntaxDocumentFilter.java
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/text/StructuredSyntaxDocumentFilter.java
@@ -283,7 +283,7 @@ public class StructuredSyntaxDocumentFilter extends DocumentFilter {
// tabs with spaces (I hate tabs)
private String replaceMetaCharacters(String string) {
// just in case remove carriage returns
- string = string.replaceAll("\\t", TAB_REPLACEMENT);
+ string = string.replace("\\t", TAB_REPLACEMENT);
return string;
}
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/DocCommand.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/DocCommand.groovy
index 6923aeb..ecfaa9c 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/DocCommand.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/DocCommand.groovy
@@ -93,7 +93,7 @@ class DocCommand extends CommandSupport {
}
protected String normalizeClassName(String className) {
- className.replaceAll('"', '').replaceAll("'", '')
+ className.replace('"', '').replace("'", '')
}
protected void browse(List urls) {
@@ -136,7 +136,7 @@ class DocCommand extends CommandSupport {
protected List urlsFor(String className) {
String groovyVersion = GroovySystem.version
- def path = className.replaceAll(/\./, '/') + '.html'
+ def path = className.replace('.', '/') + '.html'
def urls = []
if (className.matches(/^(groovy|org\.codehaus\.groovy|)\..+/)) {
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/ImportCommand.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/ImportCommand.groovy
index 9f7b928..e85a41e 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/ImportCommand.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/commands/ImportCommand.groovy
@@ -101,7 +101,7 @@ class ImportCommand extends CommandSupport {
fail(msg)
}
// remove last semicolon
- importSpec = importSpec.replaceAll(';', '')
+ importSpec = importSpec.replace(';', '')
def buff = ['import ' + args.join(' ')]
buff << 'def dummp = false'
diff --git a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
index e0306d9..cc17dda 100644
--- a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
+++ b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
@@ -521,7 +521,7 @@ class SwingBuilder extends FactoryBuilderSupport {
def condition = attributes.remove("condition") ?: JComponent.WHEN_FOCUSED
if (condition instanceof GString) condition = condition as String
if( condition instanceof String ) {
- condition = condition.toUpperCase().replaceAll(" ","_")
+ condition = condition.toUpperCase().replace(" ", "_")
if( !condition.startsWith("WHEN_") ) condition = "WHEN_"+condition
}
switch(condition) {
[groovy] 04/04: Use StringBuilder#append(char[] str, int offset,
int len) to improve performance.
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 6645f62a16baa093d5735377c913831f548f972a
Author: Pascal Schumacher <pa...@gmx.net>
AuthorDate: Thu Jan 16 23:55:31 2020 +0100
Use StringBuilder#append(char[] str, int offset, int len) to improve performance.
(cherry picked from commit 8480a596f15034f44bb4461c4e351c553dbc259d)
---
src/main/java/org/codehaus/groovy/ast/GenericsType.java | 2 +-
src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java | 4 ++--
.../groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java | 2 +-
.../groovy-sql/src/main/java/groovy/sql/ExtractIndexAndSql.java | 2 +-
.../src/main/groovy/groovy/swing/factory/ActionFactory.groovy | 2 +-
.../main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java | 2 +-
6 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 585cf57..700204f 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -113,7 +113,7 @@ public class GenericsType extends ASTNode {
ret.append(genericsBounds(theType.getOuterClass(), new HashSet<>()));
}
ret.append('.');
- ret.append(theType.getName().substring(parentClassNodeName.length() + 1));
+ ret.append(theType.getName(), parentClassNodeName.length() + 1, theType.getName().length());
} else {
ret.append(theType.getName());
}
diff --git a/src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java b/src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java
index a95258c..9840317 100644
--- a/src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/tools/LoaderConfiguration.java
@@ -192,9 +192,9 @@ public class LoaderConfiguration {
}
if (propertyIndexStart == -1 || propertyIndexStart >= str.length()) {
- result.append(str.substring(propertyIndexEnd));
+ result.append(str, propertyIndexEnd, str.length());
} else if (propertyIndexEnd == -1) {
- result.append(str.substring(propertyIndexStart));
+ result.append(str, propertyIndexStart, str.length());
}
return result.toString();
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index ccc6efe..1119936 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -1153,7 +1153,7 @@ public class Groovyc extends MatchingTask {
sb.append(File.pathSeparatorChar);
}
if (next.startsWith(baseDir)) {
- sb.append(".").append(next.substring(baseDir.length()));
+ sb.append(".").append(next, baseDir.length(), next.length());
} else {
sb.append(next);
}
diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/ExtractIndexAndSql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/ExtractIndexAndSql.java
index 8694ec6..16d7cb9 100644
--- a/subprojects/groovy-sql/src/main/java/groovy/sql/ExtractIndexAndSql.java
+++ b/subprojects/groovy-sql/src/main/java/groovy/sql/ExtractIndexAndSql.java
@@ -200,7 +200,7 @@ class ExtractIndexAndSql {
indexPropList.add(new Tuple(index, prop == null || prop.length() == 0 ? "<this>" : prop));
txtIndex = matcher.end();
}
- newSql.append(sql.substring(txtIndex)); // append ending SQL after last param.
+ newSql.append(sql, txtIndex, sql.length()); // append ending SQL after last param.
return newSql.toString();
}
diff --git a/subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ActionFactory.groovy b/subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ActionFactory.groovy
index b3fec80..3053825 100644
--- a/subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ActionFactory.groovy
+++ b/subprojects/groovy-swing/src/main/groovy/groovy/swing/factory/ActionFactory.groovy
@@ -127,7 +127,7 @@ class ActionFactory extends AbstractFactory {
}
StringBuffer buffer = new StringBuffer(text.length())
buffer.append(Character.toUpperCase(ch))
- buffer.append(text.substring(1))
+ buffer.append(text, 1, text.length())
return buffer.toString()
}
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
index cc097f3..44cfef2 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
@@ -216,7 +216,7 @@ public class StringUtils {
start = end + replLength;
end = text.indexOf(searchString, start);
}
- buf.append(text.substring(start));
+ buf.append(text, start, text.length());
return buf.toString();
}