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

"String#replace" should be preferred to "String#replaceAll" #7001

Closed
xingtanzjr opened this issue Aug 15, 2022 · 2 comments
Closed

"String#replace" should be preferred to "String#replaceAll" #7001

xingtanzjr opened this issue Aug 15, 2022 · 2 comments

Comments

@xingtanzjr
Copy link
Contributor

Code Path:
jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBDatabaseMetadata.java

The underlying implementation of String::replaceAll calls the java.util.regex.Pattern.compile() method each time it is called even if the first argument is not a regular expression. This has a significant performance cost and therefore should be used with care.

When String::replaceAll is used, the first argument should be a real regular expression. If it’s not the case, String::replace does exactly the same thing as String::replaceAll without the performance drawback of the regex.

This rule raises an issue for each String::replaceAll used with a String as first parameter which doesn’t contains special regex character or pattern.

@github-actions
Copy link

Hi, this is your first issue in IoTDB project. Thanks for your report. Welcome to join the community!

@wjr4hy
Copy link
Contributor

wjr4hy commented Aug 18, 2022

[WeOpen Star]I would like to help

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

No branches or pull requests

3 participants