Skip to content

Refactor to reuse java.util.regex.Pattern#25

Merged
wumpz merged 1 commit intojava-diff-utils:masterfrom
benelog:refactor-regex
Sep 13, 2018
Merged

Refactor to reuse java.util.regex.Pattern#25
wumpz merged 1 commit intojava-diff-utils:masterfrom
benelog:refactor-regex

Conversation

@benelog
Copy link
Copy Markdown
Contributor

@benelog benelog commented Sep 13, 2018

String.replaceAll () compiles the regular expression each time it is called.

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

It is suggested in javadoc that it is efficient to reuse the pattern, so I modified it accordingly.

If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time.

@wumpz
Copy link
Copy Markdown
Collaborator

wumpz commented Sep 13, 2018

You are right.

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