From c59d65d5027dfcbf4a5c013a9920507522809456 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Mon, 20 Jun 2016 14:40:33 -0400 Subject: [PATCH] ChangeField: Use ImmutableTable.Builder to build tables Creating a whole empty hash-based Table is a lot of garbage memory when we just copy it into an ImmutableTable, particularly since it special-cases zero- and one-element tables to save memory. Instead, use ImmutableTable.Builder, which collects its entries as a list rather than a Table. The only semantic change is this will reject duplicate cells instead of silently ignoring them. However considering that the index field was populated from a Table, there shouldn't be duplicates anyway. Change-Id: I76b5435d6bfc484cd61fb750e0802223af8756e2 --- .../google/gerrit/server/index/change/ChangeField.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/index/change/ChangeField.java b/gerrit-server/src/main/java/com/google/gerrit/server/index/change/ChangeField.java index 4baf432b76..074c81a54a 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/index/change/ChangeField.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/index/change/ChangeField.java @@ -20,9 +20,9 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Splitter; -import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableTable; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -351,8 +351,8 @@ public class ChangeField { } public static ReviewerSet parseReviewerFieldValues(Iterable values) { - Table table = - HashBasedTable.create(); + ImmutableTable.Builder b = + ImmutableTable.builder(); for (String v : values) { int f = v.indexOf(','); if (f < 0) { @@ -362,12 +362,12 @@ public class ChangeField { if (l == f) { continue; } - table.put( + b.put( ReviewerStateInternal.valueOf(v.substring(0, f)), Account.Id.parse(v.substring(f + 1, l)), new Timestamp(Long.valueOf(v.substring(l + 1, v.length())))); } - return ReviewerSet.fromTable(table); + return ReviewerSet.fromTable(b.build()); } /** Commit ID of any patch set on the change, using prefix match. */