Improvements to Hash::expand and Hash::merge.

Because of the recursion in these functions, processing very large
arrays would take a very long time. I rewrote the functions to
eliminate any unnecessary recursion and function calls. Large arrays
are now processed much faster.
Fixed coding standard violations.
Merge pull request #4787 from hperrin/master_hash_improvements

Improvements to Hash::expand and Hash::merge. (master)