schlosna commented on a change in pull request #555:
URL: https://github.com/apache/logging-log4j2/pull/555#discussion_r683117411



##########
File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java
##########
@@ -285,40 +285,40 @@ public PatternAbbreviatorFragment(
         /**
          * Abbreviate element of name.
          *
-         * @param buf      buffer to receive element.
-         * @param startPos starting index of name element.
-         * @return starting index of next element.
+         * @param input      input string which is being written to the output 
{@code buf}.
+         * @param inputIndex starting index of name element in the {@code 
input} string.
+         * @param buf        buffer to receive element.
+         * @return starting  index of next element.
          */
-        public int abbreviate(final StringBuilder buf, final int startPos) {
-            final int start = (startPos < 0) ? 0 : startPos;
-            final int max = buf.length();
-            int nextDot = -1;
-            for (int i = start; i < max; i++) {
-                if (buf.charAt(i) == '.') {
-                    nextDot = i;
-                    break;
-                }
+        int abbreviate(final String input, final int inputIndex, final 
StringBuilder buf) {
+            // ckozak: indexOf with a string is intentional. indexOf(String, 
int) appears to
+            // have optimizations that don't apply to indexOf(char, int)
+            // which result in a >10% performance improvement in some
+            // NamePatternConverterBenchmark cases. This should be 
re-evaluated with
+            // future java releases.
+            int nextDot = input.indexOf(".", inputIndex);

Review comment:
       Likely due to difference with intrinsic for `indexOf` with `String`, 
while the `char` version is not intrinsified until OpenJDK 16+, see 
https://bugs.openjdk.java.net/browse/JDK-8173585 , 
https://github.com/openjdk/jdk/commit/f71e8a61 and 
https://mail.openjdk.java.net/pipermail/jdk9-dev/2017-January/005539.html
   




-- 
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: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to