creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1484131 - /creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
Date Sat, 18 May 2013 15:47:27 GMT
Author: sebb
Date: Sat May 18 15:47:27 2013
New Revision: 1484131

URL: http://svn.apache.org/r1484131
Log:
RAT-138 RAT runs very slowly on some input
Use String matching rather than building patterns
This improves performance somewhat, but is still inefficient

Modified:
    creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java

Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java?rev=1484131&r1=1484130&r2=1484131&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
Sat May 18 15:47:27 2013
@@ -18,7 +18,7 @@
  */ 
 package org.apache.rat.analysis.license;
 
-import java.util.regex.Pattern;
+import java.util.Locale;
 
 import org.apache.rat.analysis.IHeaderMatcher;
 import org.apache.rat.analysis.RatHeaderAnalysisException;
@@ -38,7 +38,8 @@ import org.apache.rat.api.MetaData.Datum
 public class FullTextMatchingLicense extends BaseLicense
     implements IHeaderMatcher {
 
-    private Pattern fullTextPattern;
+    private String fullText;
+
     private final StringBuilder buffer = new StringBuilder();
 
     public FullTextMatchingLicense() {
@@ -53,17 +54,18 @@ public class FullTextMatchingLicense ext
     }
 
     public final void setFullText(String text) {
-        fullTextPattern = Pattern.compile(".*" + prune(text) + ".*",
-                                          Pattern.CASE_INSENSITIVE);
+        fullText = prune(text).toLowerCase(Locale.ENGLISH);
     }
 
     public final boolean hasFullText() {
-        return fullTextPattern != null;
+        return fullText != null;
     }
 
+    // TODO this is still quite inefficient if the match does not occur near the start of
the buffer
+    // see RAT-138
     public boolean match(Document subject, String line) throws RatHeaderAnalysisException
{
-        buffer.append(prune(line));
-        if (fullTextPattern.matcher(buffer).matches()) {
+        buffer.append(prune(line).toLowerCase(Locale.ENGLISH));
+        if (buffer.toString().contains(fullText)) {
             reportOnLicense(subject);
             return true;
         }



Mime
View raw message