rails/rails — pull request #17099 by sferik (2014-09-29 14:15:13+00:00)
Title: Use Hash#each_key instead of Hash#keys.each

`Hash#keys.each` allocates an array of keys; `Hash#each_key` iterates through the keys without allocating a new array. This is the reason why `Hash#each_key` exists.

This is a more comprehensive pull request that closes #17083.

###### Benchmark

```ruby
require 'benchmark/ips'

HASH = Hash[*('a'..'z')]

def slow
HASH.each_key{ |k| }
end

def fast
HASH.keys.each{ |k| }
end

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

###### Ruby 2.1.2p95

```
slow 757563.3 (±12.4%) i/s - 3721810 in 4.999106s
fast 823996.2 (±12.8%) i/s - 4032560 in 4.999773s
```

###### Ruby 2.0.0p481

```
slow 524888.2 (±12.9%) i/s - 2605078 in 5.038467s
fast 798119.1 (±11.3%) i/s - 3986304 in 5.057280s
```

###### Ruby 1.9.3p545

```
slow 534873.6 (±11.7%) i/s - 2651360 in 5.026394s
fast 796742.4 (±11.1%) i/s - 3944075 in 5.010889s
```