@Override public boolean isDirectMemory() { return bytesStore.isDirectMemory(); }
@Override public long copyTo(@NotNull BytesStore store) { if (store.isDirectMemory()) return copyToDirect(store); else return super.copyTo(store); }
static long hash(@NotNull BytesStore b) { return b.isDirectMemory() && b.bytesStore() instanceof NativeBytesStore ? OptimisedBytesStoreHash.INSTANCE.applyAsLong(b) : VanillaBytesStoreHash.INSTANCE.applyAsLong(b); }
static long hash(@NotNull BytesStore b, long length) { return b.isDirectMemory() && b.bytesStore() instanceof NativeBytesStore ? OptimisedBytesStoreHash.INSTANCE.applyAsLong(b, length) : VanillaBytesStoreHash.INSTANCE.applyAsLong(b, length); }
AbstractBytes(@NotNull BytesStore<Bytes<Underlying>, Underlying> bytesStore, long writePosition, long writeLimit, String name) throws IllegalStateException { this.bytesStore = bytesStore; bytesStore.reserve(); readPosition = bytesStore.readPosition(); this.uncheckedWritePosition(writePosition); this.writeLimit = writeLimit; // used for debugging this.name = name; assert !bytesStore.isDirectMemory() || BytesUtil.register(this); }
@NotNull @Override public Bytes<Void> write(@NotNull BytesStore bytes, long offset, long length) throws BufferUnderflowException, BufferOverflowException { assert singleThreadedAccess(); if (length == 8) writeLong(bytes.readLong(offset)); else if (bytes.isDirectMemory() && length <= Math.min(writeRemaining(), safeCopySize())) rawCopy(bytes, offset, length); else if (length > 0) BytesInternal.writeFully(bytes, offset, length, this); return this; }
@NotNull public Bytes<Underlying> write(@NotNull BytesStore bytes, long offset, long length) throws BufferOverflowException, IllegalArgumentException { if (length == 8) { writeLong(bytes.readLong(offset)); } else if (bytes.underlyingObject() == null && bytesStore .isDirectMemory() && length >= 32) { rawCopy(bytes, offset, length); } else { super.write(bytes, offset, length); } return this; }
BytesStore inBytes; long size = readRemaining(); if (this.isDirectMemory()) { inBytes = this; } else {
@NotNull private net.openhft.lang.io.Bytes toLangBytes(@NotNull BytesStore b, @NotNull Bytes tmpBytes, @NotNull net.openhft.lang.io.NativeBytes lb) { if (b.isDirectMemory()) { // check(b); lb.setStartPositionAddress(b.address(b.start()), b.address(b.readLimit())); // check(lb); } else { tmpBytes.clear(); tmpBytes.write(b); lb.setStartPositionAddress(tmpBytes.address(tmpBytes.start()), tmpBytes.address(tmpBytes.readLimit())); } return lb; }
/** * Return a Bytes which is optionally unchecked. This allows bounds checks to be turned off. * Note: this means that the result is no longer elastic, even if <code>this</code> is elastic. * * @param unchecked if true, minimal bounds checks will be performed. * @return Bytes without bounds checking. * @throws IllegalStateException if the underlying BytesStore has been released */ @NotNull default Bytes<Underlying> unchecked(boolean unchecked) throws IllegalStateException { if (unchecked) { if (isElastic()) Jvm.debug().on(getClass(), "Wrapping elastic bytes with unchecked() will require calling ensureCapacity() as needed!"); return start() == 0 && bytesStore().isDirectMemory() ? new UncheckedNativeBytes<>(this) : new UncheckedBytes<>(this); } return this; }
public void setBytes(@NotNull Bytes bytes) throws IllegalStateException { BytesStore underlyingBytes = bytes.bytesStore(); if (bytesStore != underlyingBytes) { bytesStore.release(); this.bytesStore = underlyingBytes; bytesStore.reserve(); } readPosition(bytes.readPosition()); this.uncheckedWritePosition(bytes.writePosition()); this.writeLimit = bytes.writeLimit(); assert !bytesStore.isDirectMemory() || BytesUtil.register(this); this.underlyingBytes = bytes; }
@Override public boolean equalBytes(BytesStore bytesStore, long length) throws BufferUnderflowException { if (isDirectMemory() && bytesStore instanceof VanillaBytes && bytesStore.isDirectMemory()) { @NotNull VanillaBytes b2 = (VanillaBytes) bytesStore; @NotNull NativeBytesStore nbs0 = (NativeBytesStore) this.bytesStore; @Nullable NativeBytesStore nbs2 = (NativeBytesStore) b2.bytesStore(); long i = 0; for (; i < length - 7; i += 8) { long addr0 = nbs0.address + readPosition() - nbs0.start() + i; long addr2 = nbs2.address + b2.readPosition() - nbs2.start() + i; long l0 = nbs0.memory.readLong(addr0); long l2 = nbs2.memory.readLong(addr2); if (l0 != l2) return false; } for (; i < length; i++) { long offset2 = readPosition() + i - nbs0.start(); long offset21 = b2.readPosition() + i - nbs2.start(); byte b0 = nbs0.memory.readByte(nbs0.address + offset2); byte b1 = nbs2.memory.readByte(nbs2.address + offset21); if (b0 != b1) return false; } return true; } else { return super.equalBytes(bytesStore, length); } }