diff options
author | Paulo Pinheiro <paulovictor.pinheiro@gmail.com> | 2019-10-04 00:56:29 +0200 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-10-03 15:56:29 -0700 |
commit | 842f672bafd560beeeeebed7accf196101003625 (patch) | |
tree | 457325f0457b5d4674c7500ae0ceb49b6180f50d /java | |
parent | d4cae0a62344b37908b1c157fa1cac27270ea0d0 (diff) | |
download | flatbuffers-842f672bafd560beeeeebed7accf196101003625.tar.gz flatbuffers-842f672bafd560beeeeebed7accf196101003625.tar.bz2 flatbuffers-842f672bafd560beeeeebed7accf196101003625.zip |
[FlexBuffers][Java] Cache size of Sized objects in FlexBuffers (#5551)
In my benchmarks it shows deserialization performance improvements of
around 7%
Diffstat (limited to 'java')
-rw-r--r-- | java/com/google/flatbuffers/FlexBuffers.java | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/java/com/google/flatbuffers/FlexBuffers.java b/java/com/google/flatbuffers/FlexBuffers.java index 1cd2227e..e0eb37b7 100644 --- a/java/com/google/flatbuffers/FlexBuffers.java +++ b/java/com/google/flatbuffers/FlexBuffers.java @@ -635,12 +635,16 @@ public class FlexBuffers { // Stores size in `byte_width_` bytes before end position. private static abstract class Sized extends Object { + + private final int size; + Sized(ByteBuffer buff, int end, int byteWidth) { super(buff, end, byteWidth); + size = readInt(bb, end - byteWidth, byteWidth); } public int size() { - return readInt(bb, end - byteWidth, byteWidth); + return size; } } |