Closed dubek closed 10 years ago
Early returns have always been an a bug for me, but quite frankly it seems like it needs to happen in Hamster for performance reasons.
By the way, here's the failure on travis:
1) Hamster::List doesn't give horrendously bad performance if thread realizing the list sleeps
Failure/Error: elapsed.should_not > 0.3
expected not: > 0.3
got: 0.332870754
# ./spec/lib/hamster/list/multithreading_spec.rb:46:in `block (2 levels) in <top (required)>'
Only Ruby 2.0.0.
That failure has nothing to do with this patch. Probably my clever (?) code for lazy lists performs badly under Ruby 2.0.0. Can you open an issue for that, and I'll look into it when I have time? In the meantime, I'll merge this patch.
This PR fixes the trivial case for
SortedSet#drop
andSortedSet#take
.Supposedly we can take this a step further: even for complex operations like
take_while
andfilter
and so on, we can check whether any change was made at all to the collection, and if not - returnself
. But the cost is a complication of the code. I guess we don't want to do this except in the trivial cases like in this PR.