summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 00:56:08 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-10-12 00:56:08 +0200
commitd81ca5ed1e254bc0dc4fe33a00d7ac641d9715aa (patch)
treeaa2e717c05907178e61fbf56d9a2dc29104548c8 /vespajlib
parent4cf6952345ac2fdcb9b14f1dc875a17d4fa2796d (diff)
- Presize array to its max size.
- Return the GrowableByteBuffer from TypedBinaryFormat instead of a copy of the buffer. Then buffer is copied only once instead of twice.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java
index a08e09765c8..951c23310dc 100644
--- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java
+++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java
@@ -33,9 +33,13 @@ public class TypedBinaryFormat {
public static byte[] encode(Tensor tensor) {
GrowableByteBuffer buffer = new GrowableByteBuffer();
+ encode(tensor, buffer);
+ return asByteArray(buffer);
+ }
+ public static GrowableByteBuffer encode(Tensor tensor, GrowableByteBuffer buffer) {
BinaryFormat encoder = getFormatEncoder(buffer, tensor);
encoder.encode(buffer, tensor);
- return asByteArray(buffer);
+ return buffer;
}
/**