-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SWAR technique for more efficient parsing and serialization on JV…
- Loading branch information
1 parent
44949d8
commit b1cec24
Showing
3 changed files
with
203 additions
and
260 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...la-core/jvm/src/main/java/com/github/plokhotnyuk/jsoniter_scala/core/ByteArrayAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.plokhotnyuk.jsoniter_scala.core; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
import java.nio.ByteOrder; | ||
|
||
class ByteArrayAccess { // FIXME: Use Java wrapper as w/a for missing support of @PolymorphicSignature methods in Scala 3, see: https://github.com/lampepfl/dotty/issues/11332 | ||
private static final VarHandle VH_LONG = | ||
MethodHandles.byteArrayViewVarHandle(long[].class, ByteOrder.LITTLE_ENDIAN); | ||
private static final VarHandle VH_INT = | ||
MethodHandles.byteArrayViewVarHandle(int[].class, ByteOrder.LITTLE_ENDIAN); | ||
private static final VarHandle VH_SHORT = | ||
MethodHandles.byteArrayViewVarHandle(short[].class, ByteOrder.LITTLE_ENDIAN); | ||
|
||
static void setLong(byte[] buf, int pos, long value) { | ||
VH_LONG.set(buf, pos, value); | ||
} | ||
|
||
static long getLong(byte[] buf, int pos) { | ||
return (long) VH_LONG.get(buf, pos); | ||
} | ||
|
||
static void setInt(byte[] buf, int pos, int value) { | ||
VH_INT.set(buf, pos, value); | ||
} | ||
|
||
static void setShort(byte[] buf, int pos, short value) { | ||
VH_SHORT.set(buf, pos, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.