use entrySet instead of Keyset to improve performance.

It is more efficient to use an iterator on the entrySet of the map, to avoid the Map.get(key) lookup.

Issue: SPR-12356