Skip to content

Conversation

@durigon
Copy link
Contributor

@durigon durigon commented Sep 16, 2018

If we repeatedly call String#replaceAll, we internally repeatedly call the regular expression pattern compilation every time as following:

    public String replaceAll(String regex, String replacement) {
        return Pattern.compile(regex).matcher(this).replaceAll(replacement);
    }

The modifications are to keep the compiled pattern.
Therefore, compiling a relatively expensive regular expression pattern does not have to be done every time.

If we repeatedly call String#replaceAll, we internally repeatedly call the regular expression pattern compilation every time as following:

```java
    public String replaceAll(String regex, String replacement) {
        return Pattern.compile(regex).matcher(this).replaceAll(replacement);
    }
```
The modifications are to keep the compiled pattern.
Therefore, compiling a relatively expensive regular expression pattern does not have to be done every time.
@pivotal-issuemaster
Copy link

@durigon Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 16, 2018
@pivotal-issuemaster
Copy link

@durigon Thank you for signing the Contributor License Agreement!

@philwebb philwebb added type: task A general task theme: performance Issues related to general performance and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 16, 2018
@philwebb philwebb added this to the 2.1.x milestone Sep 16, 2018
@wilkinsona wilkinsona self-assigned this Sep 17, 2018
wilkinsona added a commit that referenced this pull request Sep 17, 2018
* gh-14483:
  Use Matcher from pre-compiled Pattern rather than String for replaceAll
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.0.M4 Sep 17, 2018
@wilkinsona
Copy link
Member

@durigon Thank you very much for making your first contribution to Spring Boot. The proposed changes have been merged into master.

@durigon
Copy link
Contributor Author

durigon commented Sep 18, 2018

@wilkinsona Thank you for accepting my pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme: performance Issues related to general performance type: task A general task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants