-
Notifications
You must be signed in to change notification settings - Fork 253
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
Refactor code of WithFirstSpliterator #232
base: master
Are you sure you want to change the base?
Conversation
add couple of deprecated methods for the sake of benchmarking; add benchmarks to prove the absence of performance regression after refactoring; fix javaDocs for StreamEx.withFirst methods (actually this is not directly related to refactoring, as semantics was not changed)
|
||
private ReentrantLock lock; | ||
/* package */final class WithFirstSpliterator<T, R> extends CloneableSpliterator<R, WithFirstSpliterator<T, R>> { | ||
private static final Object lock = new Object(); |
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.
Your solution uses a single shared lock between all the spliterators, including totally independent that could possibly run in a separate thread pool. Sorry, but I cannot accept a pull-request that introduces a global lock.
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.
Indeed! My bad. Fixed this.
@@ -1764,11 +1764,6 @@ public void forPairs(BiConsumer<? super T, ? super T> action) { | |||
* <p> | |||
* This is a <a href="package-summary.html#StreamOps">quasi-intermediate | |||
* operation</a>. | |||
* | |||
* <p> | |||
* The size of the resulting stream is one element less than the input |
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.
Thanks, indeed this should be changed. I forgot to update this part in version 0.6.4 when semantics of withFirst changed. However, it's better to say that the size remains the same than removing this completely. I will apply this change separately.
is this good now ? |
Simplify the code of WithFirstSpliterator:
accept
method (as it is a one-liner) to improve readabilityTests are keep passing, perfomance is the same (even a bit higher):
WithFirstSpliteratorOld
class and new@Deprecated
methods & benchmarks are subject for removal upon merging this PR.