Skip to content

Commit a994cc0

Browse files
committed
Update readme for unsafe removal
1 parent b290d01 commit a994cc0

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ fast single primitive access and bulk transfer methods as the Slice class.
1919
Slice provides a library for interacting UTF-8 data stored in byte arrays. The UTF-8 library provides
2020
functions to count code points, substring, trim, case change, and so on.
2121

22-
## Unsafe Usage
22+
## Byte Order and Platform Compatibility
2323

24-
The Slice Library uses `sun.misc.Unsafe` to bulk transfer data between byte arrays and other array types
25-
directly as there is no other way to do this in Java today. The proposed Memory Access API (JEP 370) may
26-
provide support for this feature, and assuming performance is good, this library will be updated to use
27-
once it is available. Due to the direct usage of Unsafe, this library can only be used on a little endian
28-
CPU.
24+
This library stores multi-byte values in little-endian byte order. This is distinct from
25+
the endianness of the CPU running the code.
26+
27+
Previous versions used `sun.misc.Unsafe` to read and write multi-byte values directly
28+
to memory. This bypassed Java's abstractions and assumed the underlying CPU was
29+
little-endian. On a big-endian CPU, values would be silently corrupted.
30+
31+
This version uses VarHandles and MemorySegment, which explicitly specify little-endian
32+
byte order. These APIs handle the conversion transparently—on a big-endian CPU, Java
33+
automatically swaps bytes when reading or writing. The data format remains little-endian
34+
for compatibility, but the library now works correctly on any CPU architecture.
35+
36+
The hash functions (XxHash64, Murmur3) also use little-endian byte order, as required
37+
by their specifications.
2938

3039
# Legacy Slice
3140

0 commit comments

Comments
 (0)