8009240: RegExpScanner code is inefficient and too complex

Reviewed-by: jlaskey, lagergren
This commit is contained in:
Hannes Wallnöfer 2013-02-28 22:59:31 +01:00
parent 66c2fc6e66
commit bd2109d3fa
3 changed files with 274 additions and 741 deletions

View File

@ -117,10 +117,6 @@ public class JoniRegExp extends RegExp {
return new JoniRegExp(pattern, flags);
}
@Override
protected String replaceToken(final String str) {
return str.equals("[^]") ? "[\\s\\S]" : str;
}
}
class JoniMatcher implements RegExpMatcher {

View File

@ -67,25 +67,6 @@ public class RegExpFactory {
return new DefaultRegExp(pattern, flags);
}
/**
* Replace a regexp token as suitable for regexp instances created by this factory.
*
* @param str a regular expression token
* @return the replacement token
*/
protected String replaceToken(final String str) {
switch (str) {
case "\\s":
return "[" + Lexer.getWhitespaceRegExp() + "]";
case "\\S":
return "[^" + Lexer.getWhitespaceRegExp() + "]";
case "[^]":
return "[\\s\\S]";
default:
return str;
}
}
/**
* Compile a regexp with the given {@code source} and {@code flags}.
*
@ -98,16 +79,6 @@ public class RegExpFactory {
return instance.compile(pattern, flags);
}
/**
* Replace a regexp token as needed by the currently installed factory instance.
*
* @param token a regexp token
* @return the replacement token
*/
public static String replace(final String token) {
return instance.replaceToken(token);
}
/**
* Validate a regexp with the given {@code source} and {@code flags}.
*
@ -120,4 +91,13 @@ public class RegExpFactory {
public static void validate(final String pattern, final String flags) throws ParserException {
instance.compile(pattern, flags);
}
/**
* Returns true if the instance uses the JDK's {@code java.util.regex} package.
*
* @return true if instance uses JDK regex package
*/
public static boolean usesJavaUtilRegex() {
return instance != null && instance.getClass() == RegExpFactory.class;
}
}