[Schmitzm-commits] r2156 - in trunk/schmitzm-core: . src/main/java/de/schmitzm/regex
scm-commit at wald.intevation.org
scm-commit at wald.intevation.org
Sat Dec 8 23:09:55 CET 2012
Author: alfonx
Date: 2012-12-08 23:09:55 +0100 (Sat, 08 Dec 2012)
New Revision: 2156
Modified:
trunk/schmitzm-core/pom.xml
trunk/schmitzm-core/src/main/java/de/schmitzm/regex/RegexCache.java
Log:
Kleine weitere Dependency, um RegexCache noch etwas zu beschleunigen.
Modified: trunk/schmitzm-core/pom.xml
===================================================================
--- trunk/schmitzm-core/pom.xml 2012-12-08 21:43:32 UTC (rev 2155)
+++ trunk/schmitzm-core/pom.xml 2012-12-08 22:09:55 UTC (rev 2156)
@@ -18,7 +18,14 @@
<url>http://maven.apache.org</url>
<dependencies>
+
<dependency>
+ <groupId>com.eaio.stringsearch</groupId>
+ <artifactId>stringsearch</artifactId>
+ <version>2</version>
+ </dependency>
+
+ <dependency>
<groupId>javax.media</groupId>
<artifactId>jai_core</artifactId>
<version>1.1.3</version>
@@ -165,8 +172,16 @@
</plugin>
</plugins>
</pluginManagement>
+
+
</build>
+ <repositories>
+ <repository>
+ <id>eaio.com</id>
+ <url>http://eaio.com/maven2</url>
+ </repository>
+ </repositories>
<profiles>
<profile>
Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/regex/RegexCache.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/regex/RegexCache.java 2012-12-08 21:43:32 UTC (rev 2155)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/regex/RegexCache.java 2012-12-08 22:09:55 UTC (rev 2156)
@@ -9,6 +9,8 @@
import org.apache.solr.util.ConcurrentLRUCache;
import org.apache.solr.util.ConcurrentLRUCache.Stats;
+import com.eaio.stringsearch.BNDMCI;
+
/**
* Cached compilierte Pattern und auch Ergebnisse von RegExes. Use the matchers methods to obtain cached result and add
* regex to cache automatically.
@@ -127,11 +129,34 @@
public final boolean matches(final String regex, final Object object) {
if (object == null)
return false;
+
final String value = object instanceof String ? (String) object : object.toString();
- return result(regex, value) != null;
+ boolean canSpeedup = true;
+
+ if (regex.length() > 32 || looksLikeRegex(regex))
+ canSpeedup = false;
+
+ if (canSpeedup) {
+ int idx = new BNDMCI().searchString(value, regex);
+ return idx >= 0;
+ } else {
+ return result(regex, value) != null;
+ }
}
+ private boolean looksLikeRegex(final String regex) {
+ return RegexCache.getInstance().matches("[\\[\\]()?\\\\+{}]", regex);
+ }
+
+ // public final boolean matches(final String regex, final Object object) {
+ // if (object == null)
+ // return false;
+ // final String value = object instanceof String ? (String) object : object.toString();
+ //
+ // return result(regex, value) != null;
+ // }
+
/**
* Will throw java exceptions when pattern won't compile.
*
@@ -151,7 +176,7 @@
|| value.length() > CACHE_VALUES_TO_RESULT_MAX_VALUE_LENGTH
|| regex.length() < CACHE_VALUES_TO_RESULT_MIN_REGEX_LENGTH
|| regex.length() > CACHE_VALUES_TO_RESULT_MAX_REGEX_LENGTH) {
-
+
final Matcher m = getMatcher(regex, value);
final boolean found = m.find();
MatchResult matchResult = found ? m.toMatchResult() : null;
More information about the Schmitzm-commits
mailing list