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

Optimization: avoid using java.lang.String#replaceAll() in most cases #11

Merged
merged 1 commit into from
May 17, 2015
Merged

Optimization: avoid using java.lang.String#replaceAll() in most cases #11

merged 1 commit into from
May 17, 2015

Conversation

danielfernandez
Copy link
Contributor

Several parts of OGNL call the java.lang.String#replaceAll(...) method, which is extremely inefficient because it first compiles a java.util.regex.Pattern, then a Matcher, and finally asks this Matcher to perform the replace operation.

In order to avoid most of the calls to this method without disrupting the code base too much, I've added before each call a condition based on a call to java.lang.String#indexOf(...), which is hugely more efficient because it acts directly on the String's inner char[]. And only if this indexOf(...) determines there is a possibility that the replaceAll(...) operation would actually do something, replaceAll(...) will be called.

@lukaszlenart
Copy link
Collaborator

👍

lukaszlenart added a commit that referenced this pull request May 17, 2015
Optimization: avoid using java.lang.String#replaceAll() in most cases
@lukaszlenart lukaszlenart merged commit 0192a5d into orphan-oss:master May 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants