Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 21495a1c0 -> 6293c3e66


Improve the performance of string escaping

(cherry picked from commit 116be1e)


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

Branch: refs/heads/GROOVY_2_6_X
Commit: 6293c3e66b927e6adb5f8f8675f604d2095cd213
Parents: 21495a1
Author: sunlan <[email protected]>
Authored: Wed Jan 10 08:18:06 2018 +0800
Committer: sunlan <[email protected]>
Committed: Wed Jan 10 11:24:56 2018 +0800

----------------------------------------------------------------------
 .../groovy/parser/antlr4/util/StringUtils.java  | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6293c3e6/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/util/StringUtils.java
----------------------------------------------------------------------
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 4fe198b..4c864ba 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
@@ -32,7 +32,13 @@ import java.util.regex.Pattern;
  * Created on    2016/08/20
  */
 public class StringUtils {
+       private static final String BACKSLASH = "\\";
+
        public static String replaceHexEscapes(String text) {
+               if (!text.contains(BACKSLASH)) {
+                       return text;
+               }
+
                Pattern p = 
Pattern.compile("(\\\\*)\\\\u([0-9abcdefABCDEF]{4})");
                return StringGroovyMethods.replaceAll((CharSequence) text, p, 
new Closure<Void>(null, null) {
                        Object doCall(String _0, String _1, String _2) {
@@ -46,6 +52,10 @@ public class StringUtils {
        }
 
        public static String replaceOctalEscapes(String text) {
+               if (!text.contains(BACKSLASH)) {
+                       return text;
+               }
+
                Pattern p = Pattern.compile("(\\\\*)\\\\([0-3]?[0-7]?[0-7])");
                return StringGroovyMethods.replaceAll((CharSequence) text, p, 
new Closure<Void>(null, null) {
                        Object doCall(String _0, String _1, String _2) {
@@ -67,6 +77,10 @@ public class StringUtils {
        );
 
        public static String replaceStandardEscapes(String text) {
+               if (!text.contains(BACKSLASH)) {
+                       return text;
+               }
+
                Pattern p = Pattern.compile("(\\\\*)\\\\([btnfr\"'])");
 
                String result = StringGroovyMethods.replaceAll((CharSequence) 
text, p, new Closure<Void>(null, null) {
@@ -111,6 +125,10 @@ public class StringUtils {
        }
 
        private static String replaceEscapes(String text) {
+               if (!text.contains(BACKSLASH)) {
+                       return text;
+               }
+
                text = replace(text,"\\$", "$");
 
                text = StringUtils.replaceLineEscape(text);
@@ -119,6 +137,10 @@ public class StringUtils {
        }
 
        private static String replaceLineEscape(String text) {
+               if (!text.contains(BACKSLASH)) {
+                       return text;
+               }
+
                Pattern p = Pattern.compile("(\\\\*)\\\\\r?\n");
                text = StringGroovyMethods.replaceAll((CharSequence) text, p, 
new Closure<Void>(null, null) {
                        Object doCall(String _0, String _1) {

Reply via email to