void () { var lastMapping = ""; var lastCollection = (Collection<String>)null; for (var mapping: myInitialPathMappings) { var currentMapping = mapping.first; // If mappings are sorted, the below check should improve performance by avoiding unnecessary gets from the concurrent multi-map. if (!currentMapping.equals(lastMapping) || lastCollection == null) { lastMapping = mapping.first; lastCollection = myPathMappings.getModifiable(lastMapping); } lastCollection.add(mapping.second); } // Freeing the memory myInitialPathMappings = null; }