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
Floor for NewVectorIterator.slice limit #10518
Floor for NewVectorIterator.slice limit #10518
Conversation
4ece6e3
to
7b6cb90
Compare
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.
Looks good to me and seems pretty solid against me playing around with it.
Two things I noted:
- The infix
max
isn't used anywhere else inVector.scala
, so using the importedmmax
(mmax(until, 0)
) may be more consistent. (And maybe save one allocation? not sure..) - The slice method leaves the remaining iterator in a different state than
Iterator.slice
does. But as the Documentation ofIterator
clearly states "one should never use an iterator after calling a method on it" this seems fine.
It looks fine to me. I would tend to favor more direct logic, more like:
but the current version seems to do the same thing, just in a slightly harder-to-parse way (and doing a bit more computation in the |
take(_until) | ||
_until - from | ||
} else _until | ||
take(n) |
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.
if (until<= 0 || until<= from) Iterator.empty else {
if (from > 0) drop(from)
take(if(from < 0) until else until- from)
}
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'm unsure about your comment. Is this a third proposal? If so, I think it should be until
instead of util
, and there are some formatting and correctness issues (for instance, .slice(0,0)
returns the entire vector, so this
would need to be e.g. Iterator.empty
).
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.
Makes sense to keep things consistent. I'll change this.
I agree that it's fine. The original PR for this file clearly had a lot of thought put into performance, I'm hesitant to make changes for changes sake and limited this PR to just fixing the immediate bug. |
if(from > 0) { | ||
drop(from) | ||
until - from |
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 think the most quick fix can be mmax(util, 0)
, inline it here, otherwise lgtm.
Definitely a good habit. I wonder how much would break if each such operation on an |
@kapunga Looks like this is ready for merge — but before we do that, can you squash the two commits into one? (We don't squash-merge in this repo.) |
Fixes scala/bug#12823 Adds a floor of 0 to the limit parameter of NewVectorIterator.slice. This matches the base behavior of Iterator.slice and Vector.slice.
50320c4
to
b860d66
Compare
@SethTisue done! |
thank you @kapunga and reviewers! |
The merge has a red ex ❌ presumably unrelated to the PR.
It looks like the test relies on a weak reference and is prone to flake. |
Fixes scala/bug#12823
Adds a floor of 0 to the limit parameter of NewVectorIterator.slice. This matches the base behavior of Iterator.slice and Vector.slice.