mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-12-03 19:18:54 +01:00
160 lines
6.5 KiB
Java
160 lines
6.5 KiB
Java
package com.google.common.hash;
|
|
|
|
import ai.onnxruntime.OnnxMap$$ExternalSyntheticBUOutline0;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.primitives.Longs;
|
|
import java.lang.reflect.Field;
|
|
import java.nio.ByteOrder;
|
|
import java.security.AccessController;
|
|
import java.security.PrivilegedActionException;
|
|
import java.util.Objects;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
import org.apache.commons.lang3.SystemProperties;
|
|
import sun.misc.Unsafe;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes8.dex */
|
|
final class LittleEndianByteArray {
|
|
static final /* synthetic */ boolean $assertionsDisabled = false;
|
|
private static final LittleEndianBytes byteArray = makeGetter();
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public enum JavaLittleEndianBytes implements LittleEndianBytes {
|
|
INSTANCE { // from class: com.google.common.hash.LittleEndianByteArray.JavaLittleEndianBytes.1
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public long getLongLittleEndian(byte[] bArr, int i) {
|
|
return Longs.fromBytes(bArr[i + 7], bArr[i + 6], bArr[i + 5], bArr[i + 4], bArr[i + 3], bArr[i + 2], bArr[i + 1], bArr[i]);
|
|
}
|
|
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public void putLongLittleEndian(byte[] bArr, int i, long j) {
|
|
long j2 = 255;
|
|
for (int i2 = 0; i2 < 8; i2++) {
|
|
bArr[i + i2] = (byte) ((j & j2) >> (i2 * 8));
|
|
j2 <<= 8;
|
|
}
|
|
}
|
|
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public boolean usesFastPath() {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public interface LittleEndianBytes {
|
|
long getLongLittleEndian(byte[] bArr, int i);
|
|
|
|
void putLongLittleEndian(byte[] bArr, int i, long j);
|
|
|
|
boolean usesFastPath();
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@VisibleForTesting
|
|
public enum UnsafeByteArray implements LittleEndianBytes {
|
|
UNSAFE_LITTLE_ENDIAN { // from class: com.google.common.hash.LittleEndianByteArray.UnsafeByteArray.1
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public long getLongLittleEndian(byte[] bArr, int i) {
|
|
return UnsafeByteArray.theUnsafe.getLong(bArr, i + UnsafeByteArray.BYTE_ARRAY_BASE_OFFSET);
|
|
}
|
|
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public void putLongLittleEndian(byte[] bArr, int i, long j) {
|
|
UnsafeByteArray.theUnsafe.putLong(bArr, i + UnsafeByteArray.BYTE_ARRAY_BASE_OFFSET, j);
|
|
}
|
|
},
|
|
UNSAFE_BIG_ENDIAN { // from class: com.google.common.hash.LittleEndianByteArray.UnsafeByteArray.2
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public long getLongLittleEndian(byte[] bArr, int i) {
|
|
return Long.reverseBytes(UnsafeByteArray.theUnsafe.getLong(bArr, i + UnsafeByteArray.BYTE_ARRAY_BASE_OFFSET));
|
|
}
|
|
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public void putLongLittleEndian(byte[] bArr, int i, long j) {
|
|
UnsafeByteArray.theUnsafe.putLong(bArr, i + UnsafeByteArray.BYTE_ARRAY_BASE_OFFSET, Long.reverseBytes(j));
|
|
}
|
|
};
|
|
|
|
private static final int BYTE_ARRAY_BASE_OFFSET;
|
|
private static final Unsafe theUnsafe;
|
|
|
|
static {
|
|
Unsafe unsafe = getUnsafe();
|
|
theUnsafe = unsafe;
|
|
BYTE_ARRAY_BASE_OFFSET = unsafe.arrayBaseOffset(byte[].class);
|
|
if (unsafe.arrayIndexScale(byte[].class) == 1) {
|
|
return;
|
|
}
|
|
Buffer$$ExternalSyntheticBUOutline0.m$2();
|
|
}
|
|
|
|
private static Unsafe getUnsafe() {
|
|
try {
|
|
try {
|
|
return Unsafe.getUnsafe();
|
|
} catch (PrivilegedActionException e) {
|
|
OnnxMap$$ExternalSyntheticBUOutline0.m("Could not initialize intrinsics", e.getCause());
|
|
return null;
|
|
}
|
|
} catch (SecurityException unused) {
|
|
return (Unsafe) AccessController.doPrivileged(new LittleEndianByteArray$UnsafeByteArray$$ExternalSyntheticLambda0());
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static /* synthetic */ Unsafe lambda$getUnsafe$0() throws Exception {
|
|
for (Field field : Unsafe.class.getDeclaredFields()) {
|
|
field.setAccessible(true);
|
|
Object obj = field.get(null);
|
|
if (Unsafe.class.isInstance(obj)) {
|
|
return (Unsafe) Unsafe.class.cast(obj);
|
|
}
|
|
}
|
|
throw new NoSuchFieldError("the Unsafe");
|
|
}
|
|
|
|
@Override // com.google.common.hash.LittleEndianByteArray.LittleEndianBytes
|
|
public boolean usesFastPath() {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private LittleEndianByteArray() {
|
|
}
|
|
|
|
public static int load32(byte[] bArr, int i) {
|
|
return ((bArr[i + 3] & 255) << 24) | (bArr[i] & 255) | ((bArr[i + 1] & 255) << 8) | ((bArr[i + 2] & 255) << 16);
|
|
}
|
|
|
|
public static long load64(byte[] bArr, int i) {
|
|
return byteArray.getLongLittleEndian(bArr, i);
|
|
}
|
|
|
|
public static long load64Safely(byte[] bArr, int i, int i2) {
|
|
long j = 0;
|
|
for (int i3 = 0; i3 < Math.min(i2, 8); i3++) {
|
|
j |= (bArr[i + i3] & 255) << (i3 * 8);
|
|
}
|
|
return j;
|
|
}
|
|
|
|
public static LittleEndianBytes makeGetter() {
|
|
try {
|
|
if (Objects.equals(System.getProperty(SystemProperties.OS_ARCH), "amd64")) {
|
|
return ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN) ? UnsafeByteArray.UNSAFE_LITTLE_ENDIAN : UnsafeByteArray.UNSAFE_BIG_ENDIAN;
|
|
}
|
|
} catch (Throwable unused) {
|
|
}
|
|
return JavaLittleEndianBytes.INSTANCE;
|
|
}
|
|
|
|
public static void store64(byte[] bArr, int i, long j) {
|
|
byteArray.putLongLittleEndian(bArr, i, j);
|
|
}
|
|
|
|
public static boolean usingFastPath() {
|
|
return byteArray.usesFastPath();
|
|
}
|
|
}
|