Repository: groovy
Updated Branches:
  refs/heads/master 5d742fdc5 -> 116be1e88


Improve the performance of string escaping


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

Branch: refs/heads/master
Commit: 116be1e885edb761c12f8c2ad85deab4941f6f5e
Parents: 5d742fd
Author: sunlan <[email protected]>
Authored: Wed Jan 10 08:18:06 2018 +0800
Committer: sunlan <[email protected]>
Committed: Wed Jan 10 08:18:06 2018 +0800

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


http://git-wip-us.apache.org/repos/asf/groovy/blob/116be1e8/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 cc1f2b7..fc934fe 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