Merge change 4798

* changes:
  Replace an iterator with a traditional for loop, to reduce object allocations and memory usage.