asoldano commented on a change in pull request #407: [CXF-7716] Reduce
StringBuilders and other performance changes.
URL: https://github.com/apache/cxf/pull/407#discussion_r182964151
##########
File path:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
##########
@@ -130,10 +130,31 @@ public String getPatternValue() {
private static String escapeCharacters(String expression) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < expression.length(); i++) {
- char ch = expression.charAt(i);
- sb.append(isReservedCharacter(ch) ? "\\" + ch : ch);
+ int length = expression.length();
Review comment:
This being micro-optimization or not should really be supported by benchmark
result data. If this is on a hot path, creating less StringBuilder can really
make some differences.
This said, please note that the fix actually solves 2 issue:
1) it avoids creating the StringBuilder when not needed
2) it prevents useless StringBuilder instances being created whenever a
reserved character is found, as sb.append(isReservedCharacter(ch) ? "\\" + ch :
ch) internally creates another StringBuilder to perform the "\\" + ch
concatenation.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services