Code is called heavily, and in tests where we do it 100's of times it wa...

...s showing as a hotspot. Keep the mutable map local to the function