diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-10-12 00:56:08 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-10-12 00:56:08 +0200 |
commit | d81ca5ed1e254bc0dc4fe33a00d7ac641d9715aa (patch) | |
tree | aa2e717c05907178e61fbf56d9a2dc29104548c8 /vespajlib/src | |
parent | 4cf6952345ac2fdcb9b14f1dc875a17d4fa2796d (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/src')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/TypedBinaryFormat.java | 6 |
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; } /** |