Permalink
Browse files

avoid creating range objects

  • Loading branch information...
1 parent eb3f81f commit 96525d632d47847ae5a8d6658ad396b74ecfb6f1 @tenderlove tenderlove committed May 29, 2011
Showing with 1 addition and 1 deletion.
  1. +1 −1 activesupport/lib/active_support/core_ext/array/access.rb
@@ -16,7 +16,7 @@ def from(position)
# %w( a b c d ).to(10) # => %w( a b c d )
# %w().to(0) # => %w()
def to(position)
- self[0..position]
+ self.first position + 1
end
# Equal to <tt>self[1]</tt>.

3 comments on commit 96525d6

Contributor

alindeman replied May 29, 2011

Interesting. Is this a performance issue?

Owner

tenderlove replied May 29, 2011

Hasn't shown up on any benchmarks, but adding two numbers is definitely cheaper than creating a new object.

Please sign in to comment.