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 2024/06/15 20:21:29 UTC

(groovy) branch master updated: Avoid compiling regex repeatedly

This is an automated email from the ASF dual-hosted git repository.

sunlan 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 13f14c2b80 Avoid compiling regex repeatedly
13f14c2b80 is described below

commit 13f14c2b80c10cbe0fdbf03d0ebce03ce9dd3ea4
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Jun 16 05:21:01 2024 +0900

    Avoid compiling regex repeatedly
---
 src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 179573f116..f5067671a9 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -3439,7 +3439,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
         if (self == null) {
             return true;
         }
-        return self.toString().matches("\\s*");
+        return matches(self, LazyInitializer.BLANK_PATTERN);
     }
 
     /**
@@ -3978,4 +3978,8 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
 
         return self.toString().toLowerCase().contains(searchString.toString().toLowerCase());
     }
+
+    private static class LazyInitializer {
+        static final Pattern BLANK_PATTERN = Pattern.compile("\\s*");
+    }
 }