On 03/04/2015 02:29 PM, Andrew Haley wrote: >> My inclination is to remove the get*Unaligned(..., boolean >> bigEndian) methods and thereby consistently use Bits.swap in the >> heap buffer. A similar pattern applies for float/double conversion. > > I suggest that you and John argue that between yourselves! I think > there's a lot to be said for that approach on architectures which can > do unaligned accesses and have big- and little-endian memory > operators.
The new API gives us HeapByteBuffer methods public long getLong(int i) { return unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8)), bigEndian); } If we get rid of the get*Unaligned(..., boolean bigEndian) methods we'll end up with public long getLong(int i) { long x = unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8))); return nativeByteOrder ? x : Bits.swap(x)); } ... which has the disadvantage that all of the Buffer methods have to know about the native endianness. One suggestion: if we exposed Unsafe.fromEndian we could do something like public long getLong(int i) { long x = unsafe.getLongUnaligned(hb, byteOffset(checkIndex(i, 8))); return unsafe.fromEndian(bigEndian, x)); } Andrew.