Inefficient use of keySet iterator instead of entrySet iterator
PATCH 1/1 Inefficient use of keySet iterator instead of entrySet iterator
Quoted 1 line
From FindBugs:
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.
Signed-off-by Yann Simon <[email protected]>
--- .../src/org/spearce/jgit/lib/ObjectIdMap.java | 5 +++-- .../src/org/spearce/jgit/transport/AmazonS3.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
org.spearce.jgit/src/org/spearce/jgit/lib/ObjectIdMap.java +3 -2
@@ -183,8 +183,9 @@ public V put(ObjectId key, V value) { } public void putAll(Map<? extends ObjectId, ? extends V> arg0) { - for (ObjectId k : arg0.keySet()) { - V v=arg0.get(k); + for (Map.Entry<? extends ObjectId, ? extends V> entry : arg0.entrySet()) { + ObjectId k = entry.getKey(); + V v=entry.getValue(); put(k,v); } }
org.spearce.jgit/src/org/spearce/jgit/transport/AmazonS3.java +3 -2
@@ -572,9 +572,10 @@ private HttpURLConnection open(final String method, final String bucket, private void authorize(final HttpURLConnection c) throws IOException { final Map<String, List<String>> reqHdr = c.getRequestProperties(); final SortedMap<String, String> sigHdr = new TreeMap<String, String>(); - for (final String hdr : reqHdr.keySet()) { + for (final Map.Entry<String, List<String>> entry : reqHdr.entrySet()) { + final String hdr = entry.getKey(); if (isSignedHeader(hdr)) - sigHdr.put(hdr.toLowerCase(), toCleanString(reqHdr.get(hdr))); + sigHdr.put(hdr.toLowerCase(), toCleanString(entry.getValue())); } final StringBuilder s = new StringBuilder();
Signature · 1 line
1.6.1.2