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.
Merge pull request #17099 from sferik/each_key

Use Hash#each_key instead of Hash#keys.each