diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2019-04-26 14:16:16 +0200 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2019-04-26 14:16:16 +0200 |
commit | 12aae4a257f8762d56d3ebe7f67ce7d27fa6f2f1 (patch) | |
tree | d810bb639e2ea8379a7d6390d0c63300a507c279 /container-search/src/main/java/com/yahoo/search/dispatch/rpc | |
parent | 5f6a5a5d626808459bc65c95eb226e746ed3d18f (diff) |
Avoid dynamic ArrayList growth in HitGroup when number of hits is known
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/dispatch/rpc')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java index 033b507b4a4..76da9fbc1f7 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java @@ -168,10 +168,17 @@ public class ProtobufSerialization { result.setTotalHitCount(protobuf.getTotalHitCount()); result.setCoverage(convertToCoverage(protobuf)); - if (protobuf.getGroupingBlob() != null && !protobuf.getGroupingBlob().isEmpty()) { - ArrayList<Grouping> list = new ArrayList<>(); + int hitItems = protobuf.getHitsCount(); + var haveGrouping = protobuf.getGroupingBlob() != null && !protobuf.getGroupingBlob().isEmpty(); + if(haveGrouping) { + hitItems++; + } + result.hits().ensureCapacity(hitItems); + + if (haveGrouping) { BufferSerializer buf = new BufferSerializer(new GrowableByteBuffer(protobuf.getGroupingBlob().asReadOnlyByteBuffer())); int cnt = buf.getInt(null); + ArrayList<Grouping> list = new ArrayList<>(cnt); for (int i = 0; i < cnt; i++) { Grouping g = new Grouping(); g.deserialize(buf); |