On Thu, 20 Jul 2023 09:39:09 GMT, Maurizio Cimadamore <[email protected]>
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