This is an automated email from the ASF dual-hosted git repository.
robertwb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new 80ae93217c5 Minor optimization for the common case of merging empty
string sets. (#31803)
80ae93217c5 is described below
commit 80ae93217c5ac74e41cbedaeea7806fb0f05c2a9
Author: Robert Bradshaw <[email protected]>
AuthorDate: Mon Aug 5 09:49:55 2024 -0700
Minor optimization for the common case of merging empty string sets.
(#31803)
---
.../apache/beam/runners/core/metrics/StringSetData.java | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git
a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/StringSetData.java
b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/StringSetData.java
index 93dfb8e3ebc..466d4ad46eb 100644
---
a/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/StringSetData.java
+++
b/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/StringSetData.java
@@ -19,7 +19,6 @@ package org.apache.beam.runners.core.metrics;
import com.google.auto.value.AutoValue;
import java.io.Serializable;
-import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@@ -50,12 +49,16 @@ public abstract class StringSetData implements Serializable
{
* Combines this {@link StringSetData} with other, both original
StringSetData are left intact.
*/
public StringSetData combine(StringSetData other) {
- // do not merge other on this as this StringSetData might hold an
immutable set like in case
- // of EmptyStringSetData
- Set<String> combined = new HashSet<>();
- combined.addAll(this.stringSet());
- combined.addAll(other.stringSet());
- return StringSetData.create(combined);
+ if (this.stringSet().isEmpty()) {
+ return other;
+ } else if (other.stringSet().isEmpty()) {
+ return this;
+ } else {
+ ImmutableSet.Builder<String> combined = ImmutableSet.builder();
+ combined.addAll(this.stringSet());
+ combined.addAll(other.stringSet());
+ return StringSetData.create(combined.build());
+ }
}
/**