188 }
189
190 // check correction
191 for (var id : visitor.idCommentMap.keySet()) {192 LOG.debug("id: {}", id);
193
194 List<Token> comments = visitor.idCommentMap.get(id);
171 expectedIdCommentMap.put("linkageSpecification4", "linkageSpecification4");
172
173 // check completeness
174 for (var id : expectedIdCommentMap.keySet()) {175 LOG.debug("id: {}", id);
176
177 List<Token> comments = visitor.idCommentMap.get(id);
This method accesses the value of a Map entry, using a key that was retrieved from a keySet
iterator.
It is more efficient to use an iterator on the entrySet
of the map, to avoid the Map.get(key)
lookup.
for (String key: map.keySet()) {
...
if (satisfiesCriteria(key))
value = map.get(key); // Inefficient
...
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
...
if (satisfiesCriteria(entry.getKey())
value = entry.getValue();
...
}
While the performance benefits of this change may not be very high for smaller maps, it is worth making this change if you will be handling maps with very large capacities (entry count in the millions for example), and/or slower or bad hashing implementations.