You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-dev@jakarta.apache.org by df...@apache.org on 2006/04/01 18:53:46 UTC
svn commit: r390695 - in /jakarta/oro/trunk: CHANGES
src/java/org/apache/oro/text/perl/Perl5Util.java
Author: dfs
Date: Sat Apr 1 08:53:45 2006
New Revision: 390695
URL: http://svn.apache.org/viewcvs?rev=390695&view=rev
Log:
Changed Perl5Util MatchResult instances produced by getMatch() to be thread-local.
Modified:
jakarta/oro/trunk/CHANGES
jakarta/oro/trunk/src/java/org/apache/oro/text/perl/Perl5Util.java
Modified: jakarta/oro/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/jakarta/oro/trunk/CHANGES?rev=390695&r1=390694&r2=390695&view=diff
==============================================================================
--- jakarta/oro/trunk/CHANGES (original)
+++ jakarta/oro/trunk/CHANGES Sat Apr 1 08:53:45 2006
@@ -1,6 +1,8 @@
$Id$
Version 2.1-dev-1
+ o Perl5Util.getMatch() now returns a thread-local result.
+
o broke up the master jar files into separate components:
jakarta-oro : all classes
jakarta-oro-core : required interfaces
Modified: jakarta/oro/trunk/src/java/org/apache/oro/text/perl/Perl5Util.java
URL: http://svn.apache.org/viewcvs/jakarta/oro/trunk/src/java/org/apache/oro/text/perl/Perl5Util.java?rev=390695&r1=390694&r2=390695&view=diff
==============================================================================
--- jakarta/oro/trunk/src/java/org/apache/oro/text/perl/Perl5Util.java (original)
+++ jakarta/oro/trunk/src/java/org/apache/oro/text/perl/Perl5Util.java Sat Apr 1 08:53:45 2006
@@ -110,16 +110,11 @@
* the last {@link org.apache.oro.text.regex.MatchResult MatchResult}
* found (which can be accessed with {@link #getMatch()}) by a match or
* substitution (or even a split, but this isn't particularly useful).
- * At the moment, the
+ * The
* {@link org.apache.oro.text.regex.MatchResult MatchResult} returned
- * by {@link #getMatch()} is not stored in a thread-local variable. Therefore
- * concurrent calls to {@link #getMatch()} will produce unpredictable
- * results. So if your concurrent program requires the match results,
- * you must protect the matching and the result retrieval in a critical
- * section. If you do not need match results, you don't need to do anything
- * special. If you feel the J2SE implementation of {@link #getMatch()}
- * should use a thread-local variable and obviate the need for a critical
- * section, please express your views on the oro-dev mailing list.
+ * by {@link #getMatch()} is stored in a thread-local variable. Therefore
+ * concurrent calls to {@link #getMatch()} will produce the last match
+ * found by the calling thread.
*
* @version @version@
* @since 1.0
@@ -141,7 +136,8 @@
/** The compiled match expression parsing regular expression. */
private Pattern __matchPattern;
/** The last match from a successful call to a matching method. */
- private MatchResult __lastMatch;
+ private ThreadLocal __lastMatch;
+
/**
* A container for temporarily holding the results of a split before
* deleting trailing empty fields.
@@ -192,6 +188,7 @@
public Perl5Util(PatternCache cache) {
__splitList = new ArrayList();
__matcher = new Perl5Matcher();
+ __lastMatch = new ThreadLocal();
__patternCache = cache;
__expressionCache = new CacheLRU(cache.capacity());
__compilePatterns();
@@ -333,7 +330,7 @@
result = __matcher.contains(input, __parseMatchExpression(pattern));
if(result) {
- __lastMatch = __matcher.getMatch();
+ __lastMatch.set(__matcher.getMatch());
__originalInput = input;
__inputBeginOffset = 0;
__inputEndOffset = input.length;
@@ -428,7 +425,7 @@
result = __matcher.contains(input, __parseMatchExpression(pattern));
if(result) {
- __lastMatch = __matcher.getMatch();
+ __lastMatch.set(__matcher.getMatch());
__originalInput = input.getInput();
__inputBeginOffset = input.getBeginOffset();
__inputEndOffset = input.getEndOffset();
@@ -450,7 +447,7 @@
* last match found.
*/
public synchronized MatchResult getMatch() {
- return __lastMatch;
+ return (MatchResult)__lastMatch.get();
}
@@ -564,7 +561,7 @@
Util.substitute(result, __matcher, entry._pattern, entry._substitution,
input, entry._numSubstitutions);
- __lastMatch = __matcher.getMatch();
+ __lastMatch.set(__matcher.getMatch());
return subCount;
}
@@ -670,7 +667,7 @@
Util.substitute(result, __matcher, compiledPattern, substitution,
input, numSubstitutions);
- __lastMatch = __matcher.getMatch();
+ __lastMatch.set(__matcher.getMatch());
return subCount;
}
@@ -821,7 +818,7 @@
__splitList.clear();
// Just for the sake of completeness
- __lastMatch = currentResult;
+ __lastMatch.set(currentResult);
}
/**
@@ -958,7 +955,8 @@
* @return The length of the last match found.
*/
public synchronized int length() {
- return __lastMatch.length();
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.length();
}
/**
@@ -968,7 +966,8 @@
* the entire match itself.
*/
public synchronized int groups() {
- return __lastMatch.groups();
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.groups();
}
@@ -984,7 +983,8 @@
* of length 0.
*/
public synchronized String group(int group) {
- return __lastMatch.group(group);
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.group(group);
}
/**
@@ -1000,7 +1000,8 @@
* use the offset to index an array or String.
*/
public synchronized int begin(int group) {
- return __lastMatch.begin(group);
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.begin(group);
}
@@ -1015,7 +1016,8 @@
* string will return its start offset.
*/
public synchronized int end(int group) {
- return __lastMatch.end(group);
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.end(group);
}
@@ -1030,7 +1032,8 @@
* not exist, returns -1.
*/
public synchronized int beginOffset(int group) {
- return __lastMatch.beginOffset(group);
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.beginOffset(group);
}
/**
@@ -1045,7 +1048,8 @@
* string will return its start offset.
*/
public synchronized int endOffset(int group) {
- return __lastMatch.endOffset(group);
+ MatchResult match = (MatchResult)__lastMatch.get();
+ return match.endOffset(group);
}
/**
@@ -1054,9 +1058,10 @@
* @return A string containing the entire match.
*/
public synchronized String toString() {
- if(__lastMatch == null)
+ MatchResult match = (MatchResult)__lastMatch.get();
+ if(match == null)
return null;
- return __lastMatch.toString();
+ return match.toString();
}
@@ -1071,7 +1076,7 @@
if(__originalInput == null)
return __nullString;
- begin = __lastMatch.beginOffset(0);
+ begin = beginOffset(0);
if(begin <= 0)
return __nullString;
@@ -1115,7 +1120,7 @@
if(__originalInput == null)
return __nullString;
- end = __lastMatch.endOffset(0);
+ end = endOffset(0);
if(end < 0)
return __nullString;
@@ -1163,7 +1168,7 @@
if(__originalInput == null)
return null;
- begin = __lastMatch.beginOffset(0);
+ begin = beginOffset(0);
if(begin <= 0)
return null;
@@ -1214,7 +1219,7 @@
if(__originalInput == null)
return null;
- end = __lastMatch.endOffset(0);
+ end = endOffset(0);
if(end < 0)
return null;
---------------------------------------------------------------------
To unsubscribe, e-mail: oro-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: oro-dev-help@jakarta.apache.org