

I think the above patch is reasonable to put back into the JDK while we investigate if/how C2 can better handle this pattern. The codePoints () method of IntStream class is used to get a stream of code point values from the given sequence. String concatenation is implemented through the StringBuilder (or StringBuffer ) class and its append method.

There's likely a compiler bug hiding in plain sight here where the potentially uninitialized local `char c` messes up the loop optimization of the second loop. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. We see that the patch above helps in general, but mainly improves the microbenchmark that spends its time in the second loop. encodeUTF16LongStart tests the same string but with the non-ASCII codepoint moved to the front. This exaggerates the usefulness of the ascii loop. The micro encodeUTF16LongEnd encodes a longer string which is mostly ASCII but with an non-ASCII codepoint at the end. Going back, this seem to have been an issue with this code since its inception with JEP 254 in JDK 9. Results on a few micros I'm updating to better stress this code -īenchmark (charsetName) Mode Cnt Score Error Units

+ char c = StringUTF16.getChar(val, sp++) grep 'Exception' application.log grep -V 'Server Exception' tail -10 2. These methods can be used as a chain of the pipeline with complex logic similar to the UNIX pipeline command as below. This iterator can be called as New Fancy Iterator. +++ -1284,14 +1284,17 public final class String This API provides several methods to iterate over a stream. Disallow characters which are made with multiple code points in character.
#JAVA ITERATE STRING CODEPOINTS UPDATE#
a/src/java.base/share/classes/java/lang/String.java Enforce for loop update clause moving the counter in the right direction. I narrowed it down to something as straightforward as this:ĭiff -git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java While making an attempt to replace the ASCII fast loop in `String.encodeUTF8_UTF16` I noticed that altering the shape of the code so that char c is scope local to each loop helps the performance of the method by helping C2 optimize each loop better.
