-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Optimized Array#skip #6946
Optimized Array#skip #6946
Conversation
BTW, maybe we should rename |
"BTW, maybe we should rename skip to drop, it reads better." Also, |
src/array.cr
Outdated
@@ -946,6 +946,17 @@ class Array(T) | |||
self | |||
end | |||
|
|||
# Optimized version of `Enumerable#skip`. |
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.
Shouldn't this better repeat the description of Enumerable#skip
?
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.
Yes. Actually, we should have some thingy to inherit doc from the parent. Let's work on that next (there are already a few methods in Array
that say they are an optimized version of something else)
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.
For now I think it's better indeed, but it would be nice to have a :previous_doc:
and/or :super_doc:
to automatically copy the doc from previous def or super def or that same method
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 just copied the doc.
@yxhuvud Yeah, |
b1a59e7
to
e45ec4c
Compare
Ah right. We have |
Enumerable#skip
doesn't know the size of the resulting array, plus it's much efficient to do a mem-copy here.A benchmark I did:
where
skip
is the current one,skip2
just called[count..-1]
andskip3
is the version in this PR.Results: