Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize parsing by creating static regex patterns #38

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions svg-core/src/main/java/com/kitfox/svg/SVGElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,10 @@ public StyleAttribute getPresAbsolute(String styName)
return (StyleAttribute) presAttribs.get(styName);
}

private static final Pattern TRANSFORM_PATTERN = Pattern.compile("\\w+\\([^)]*\\)");
static protected AffineTransform parseTransform(String val) throws SVGException
{
final Matcher matchExpression = Pattern.compile("\\w+\\([^)]*\\)").matcher("");
final Matcher matchExpression = TRANSFORM_PATTERN.matcher("");

AffineTransform retXform = new AffineTransform();

Expand All @@ -758,9 +759,10 @@ static protected AffineTransform parseTransform(String val) throws SVGException
return retXform;
}

private static final Pattern WORD_PATTERN = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)");
static public AffineTransform parseSingleTransform(String val) throws SVGException
{
final Matcher matchWord = Pattern.compile("([a-zA-Z]+|-?\\d+(\\.\\d+)?(e-?\\d+)?|-?\\.\\d+(e-?\\d+)?)").matcher("");
final Matcher matchWord = WORD_PATTERN.matcher("");

AffineTransform retXform = new AffineTransform();

Expand Down Expand Up @@ -839,9 +841,10 @@ static protected float nextFloat(LinkedList<String> l)
return Float.parseFloat(s);
}

private static final Pattern COMMAND_PATTERN = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)");
static protected PathCommand[] parsePathList(String list)
{
final Matcher matchPathCmd = Pattern.compile("([MmLlHhVvAaQqTtCcSsZz])|([-+]?((\\d*\\.\\d+)|(\\d+))([eE][-+]?\\d+)?)").matcher(list);
final Matcher matchPathCmd = COMMAND_PATTERN.matcher(list);

//Tokenize
LinkedList<String> tokens = new LinkedList<String>();
Expand Down