Skip to content

Commit

Permalink
Avoid making a copy in mergeMaps if one of the input maps is empty.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 615354375
Change-Id: I6914444b5e4cd30e8519a9df41eb546d3e9aaa81
  • Loading branch information
justinhorvitz authored and fmeum committed Mar 14, 2024
1 parent 2288c9c commit 3e8ee27
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ default ImmutableMap<String, String> getExecutionInfo() {

static ImmutableMap<String, String> mergeMaps(
ImmutableMap<String, String> first, ImmutableMap<String, String> second) {
if (first.isEmpty()) {
return second;
}
if (second.isEmpty()) {
return first;
}
return ImmutableMap.<String, String>builderWithExpectedSize(first.size() + second.size())
.putAll(first)
.putAll(second)
Expand Down

0 comments on commit 3e8ee27

Please sign in to comment.