You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "ChristopherSchultz (via GitHub)" <gi...@apache.org> on 2023/02/03 15:18:03 UTC
[GitHub] [tomcat] ChristopherSchultz commented on pull request #581: Speedup by removing non pattern replaceAll with constant arg
ChristopherSchultz commented on PR #581:
URL: https://github.com/apache/tomcat/pull/581#issuecomment-1416015385
There isn't much of a difference between `String.replace` and `String.replaceAll`. They both use regular expressions under the hood. Java's `Pattern` class has a special case for "this search-string doesn't include any metacharacters" (it's a flag called `LITERAL`) and has optimized code-paths for those cases.
IMO `replaceAll` is more clear than `replace` because it's absolutely clear that all instances will be replaced in the string.
If performance is the primary factor, here, we should use an implementation of string-replacement that does not involve creating `Pattern` and `Matcher` objects and re-encoding the replacement String _every single time_.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org