This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
The following commit(s) were added to refs/heads/master by this push:
new fc2c3fc Clear memory using putByteArray instead of fill.
new 88f7055 Merge pull request #127 from gianm/clear-via-put-bytes
fc2c3fc is described below
commit fc2c3fc4383952aad3c1e15fc076c8b58e4f86a8
Author: Gian Merlino <[email protected]>
AuthorDate: Wed Apr 14 08:39:31 2021 -0700
Clear memory using putByteArray instead of fill.
---
.../datasketches/memory/BaseWritableMemoryImpl.java | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git
a/src/main/java/org/apache/datasketches/memory/BaseWritableMemoryImpl.java
b/src/main/java/org/apache/datasketches/memory/BaseWritableMemoryImpl.java
index bf3c6b9..829fe14 100644
--- a/src/main/java/org/apache/datasketches/memory/BaseWritableMemoryImpl.java
+++ b/src/main/java/org/apache/datasketches/memory/BaseWritableMemoryImpl.java
@@ -55,11 +55,14 @@ import java.nio.channels.WritableByteChannel;
@SuppressWarnings({"restriction"})
abstract class BaseWritableMemoryImpl extends WritableMemory {
+ //1KB of empty bytes for speedy clear()
+ private final static byte[] EMPTY_BYTES;
//Static variable for cases where byteBuf/array/direct sizes are zero
final static BaseWritableMemoryImpl ZERO_SIZE_MEMORY;
static {
+ EMPTY_BYTES = new byte[1024];
ZERO_SIZE_MEMORY = new HeapWritableMemoryImpl(new byte[0], 0L, 0L,
READONLY);
}
@@ -415,12 +418,18 @@ abstract class BaseWritableMemoryImpl extends
WritableMemory {
@Override
public final void clear() {
- fill(0, getCapacity(), (byte) 0);
+ clear(0, getCapacity());
}
@Override
- public final void clear(final long offsetBytes, final long lengthBytes) {
- fill(offsetBytes, lengthBytes, (byte) 0);
+ public final void clear(final long offsetBytes, final long lengthBytes)
+ {
+ //No need to check bounds, since putByteArray calls
checkValidAndBoundsForWrite
+
+ final long endBytes = offsetBytes + lengthBytes;
+ for (long i = offsetBytes; i < endBytes; i += EMPTY_BYTES.length) {
+ putByteArray(i, EMPTY_BYTES, 0, (int) Math.min(EMPTY_BYTES.length,
endBytes - i));
+ }
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]