rails/rails — pull request #17244 by sferik (2014-10-13 11:09:57+00:00)
Title: Replace Enumerable#reverse.each with Enumerable#reverse_each

Similar to https://github.com/rails/rails/pull/17099, `Enumerable#reverse` allocates an extra array. `Enumerable#reverse_each` iterates through the keys without allocating an extra array. This is the reason why `Enumerable#reverse_each` exists.

###### Benchmark

```ruby
require 'benchmark/ips'

ARRAY = (1..100).to_a

def slow
ARRAY.reverse.each{|x| x}
end

def fast
ARRAY.reverse_each{|x| x}
end

Benchmark.ips do |x|
x.report('slow') { slow }
x.report('fast') { fast }
end
```

###### Ruby 2.1.2

```
slow 163236.3 (±8.7%) i/s - 810300 in 5.009018s
fast 186414.8 (±6.5%) i/s - 934235 in 5.035333s
```