This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 0bbdbf78ec refactor: simplify Collections.unmodifiableSet(emptySet())
to Set.of() (#3138)
0bbdbf78ec is described below
commit 0bbdbf78ecf2f99525e0a94e2667b89533915778
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Tue Jun 23 18:44:15 2026 +0800
refactor: simplify Collections.unmodifiableSet(emptySet()) to Set.of()
(#3138)
* refactor: simplify Collections.unmodifiableSet(emptySet()) to Set.of()
Motivation:
StreamOfStreams.scala uses
Collections.unmodifiableSet(Collections.emptySet[Any])
which is two method calls to create an immutable empty set.
Modification:
Replace with java.util.Set.of[Any]() which is a single call that already
returns an immutable empty set (JDK 9 factory). Remove the unused
java.util.Collections import.
Result:
Cleaner code with one call instead of two. Both approaches produce
immutable empty sets with identical semantics.
Tests:
sbt "stream/compile" — passed
References:
Refs #3136
* refactor: use Collections.emptySet directly instead of Set.of()
Motivation:
Reviewer pjfanning pointed out that `java.util.Set.of[Any]()` allocates
a new immutable empty set on every invocation, while
`java.util.Collections.emptySet[Any]` is a singleton and is already
immutable by specification.
Modification:
Replace `java.util.Set.of[Any]()` with `Collections.emptySet[Any]`.
No `Collections.unmodifiableSet` wrapper is needed because
`Collections.emptySet` is immutable by contract.
Result:
One fewer allocation per GroupBy substream creation on the
`allowClosedSubstreamRecreation = true` path, and the original
singleton semantics of the pre-existing `Collections.emptySet` are
preserved.
Tests:
sbt "stream/compile" -- passed
References:
PR #3138 review comments by @pjfanning
---
.../scala/org/apache/pekko/stream/impl/fusing/StreamOfStreams.scala | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git
a/stream/src/main/scala/org/apache/pekko/stream/impl/fusing/StreamOfStreams.scala
b/stream/src/main/scala/org/apache/pekko/stream/impl/fusing/StreamOfStreams.scala
index 882e717f5d..fdb0e1ed15 100644
---
a/stream/src/main/scala/org/apache/pekko/stream/impl/fusing/StreamOfStreams.scala
+++
b/stream/src/main/scala/org/apache/pekko/stream/impl/fusing/StreamOfStreams.scala
@@ -399,7 +399,7 @@ import pekko.util.OptionVal
lazy val decider =
inheritedAttributes.mandatoryAttribute[SupervisionStrategy].decider
private val activeSubstreamsMap = new java.util.HashMap[Any,
SubstreamSource]()
private val closedSubstreams =
- if (allowClosedSubstreamRecreation)
Collections.unmodifiableSet(Collections.emptySet[Any])
+ if (allowClosedSubstreamRecreation) Collections.emptySet[Any]
else new java.util.HashSet[Any]()
private val timeout: FiniteDuration =
inheritedAttributes.mandatoryAttribute[ActorAttributes.StreamSubscriptionTimeout].timeout
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]