RFR: 8310843: Reimplement ByteArray and ByteArrayLittleEndian with Unsafe [v10]
    Chen Liang 
    liach at openjdk.org
       
    Thu Jul 20 10:33:45 UTC 2023
    
    
  
On Thu, 20 Jul 2023 09:39:09 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Actually, a byte buffer is big endian, so some extra code would be required. But maybe that's another helper function:
>> 
>> 
>> @ForceInline
>> ByteBuffer asBuffer(byte[] array) { return ByteBuffer.wrap(array).order(ByteOrder.nativeOrder()); }
>> 
>> 
>> And then replace:
>> 
>> 
>> ByteArray.getChar(array, 42)
>> 
>> With
>> 
>> asBuffer(array).getChar(42);
>
> Also... in a lot of cases where ByteArray is used (DataXYZStream, ObjectXYZStream) the array being used is a field in the class. So the byte buffer creation can definitively be amortized (or the code changed to work on buffers instead of arrays).
The Unsafe-based writing will be used by `Integer.toString` and `Long.toString` as well; in those cases, will creating a ByteBuffer wrapper be overkill?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14636#discussion_r1269265267
    
    
More information about the core-libs-dev
mailing list