RFR: 8321279: Implement hashCode() in Heap-X-Buffer.java.template [v3]

ExE Boss duke at openjdk.org
Fri Dec 8 10:45:17 UTC 2023


On Wed, 6 Dec 2023 19:55:01 GMT, Sergey Tsypanov <stsypanov at openjdk.org> wrote:

>> Currently `Heap*Buffer.hashCode()` is inherited from `*Buffer` and implemented as 
>> 
>> public int hashCode() {
>>     int h = 1;
>>     int p = position();
>>     for (int i = limit() - 1; i >= p; i--)
>>         h = 31 * h + (int)get(i);
>>     return h;
>> }
>> 
>> This can be improved using `ArraysSupport.vectorizedHashCode()`
>
> Sergey Tsypanov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8321279: Fix hashCode()

src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 710:

> 708: 
> 709:     public int hashCode() {
> 710:         return ArraysSupport.vectorizedHashCode(hb, ix(offset), remaining(), 1, ArraysSupport.T_BYTE);

Suggestion:

        return ArraysSupport.vectorizedHashCode(hb, ix(position()), remaining(), 1, ArraysSupport.T_BYTE);

src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template line 741:

> 739: 
> 740:     public int hashCode() {
> 741:         return ArraysSupport.vectorizedHashCode(hb, ix(offset), remaining(), 1, ArraysSupport.T_CHAR);

Suggestion:

        return ArraysSupport.vectorizedHashCode(hb, ix(position()), remaining(), 1, ArraysSupport.T_CHAR);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16992#discussion_r1418062713
PR Review Comment: https://git.openjdk.org/jdk/pull/16992#discussion_r1418063246


More information about the nio-dev mailing list