On Tue, 20 Dec 2022 19:52:34 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StringUTF16.java line 418: >> >>> 416: return 0; >>> 417: } else { >>> 418: return ArraysSupport.vectorizedHashCode(value, >>> ArraysSupport.UTF16); >> >> Special case for 1 missing here. > > Intentionally left out. Array length is always even for `UTF16` arrays, but > we could add a case for `2` that'd return `getChar(bytes, 0)` but I didn't > see much of a win when I tested this. I do see a 1.5x gain with this special case added: return switch (value.length) { case 0 -> 0; case 2 -> getChar(value, 0); default -> ArraysSupport.vectorizedHashCode(value, ArraysSupport.UTF16); }; before: 0.987 ns/op after: 0.640 ns/op ------------- PR: https://git.openjdk.org/jdk/pull/10847