-
Notifications
You must be signed in to change notification settings - Fork 191
chore: Matching on seq #2561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Matching on seq #2561
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,13 +402,15 @@ object Source { | |
| * stream will see an individual flow of elements (always starting from the | ||
| * beginning) regardless of when they subscribed. | ||
| */ | ||
| def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = { | ||
| (iterable.knownSize: @switch) match { | ||
| case 0 => empty | ||
| case 1 => single(iterable.head) | ||
| case _ => | ||
| fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource) | ||
| } | ||
| def apply[T](iterable: immutable.Iterable[T]): Source[T, NotUsed] = iterable match { | ||
| case immutable.Seq() => empty[T] | ||
| case immutable.Seq(elem: T @unchecked) => single(elem) | ||
| case other => (other.knownSize: @switch) match { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment saying that if the Iterable has unknown size, that knownSize returns -1?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not unknown size,just the size can or not been cheaply cimputed |
||
| case 0 => empty | ||
| case 1 => single(iterable.head) | ||
| case _ => | ||
| fromGraph(new IterableSource[T](iterable)).withAttributes(DefaultAttributes.iterableSource) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how adding extra checks, including instanceof checks, improves performance. Is there any way that we could keep a variant of the old code from the recent other PR that introduced changes?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's vs the materialization