All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann Simon <yann.simon.fr@gmail.com>
To: Robin Rosenberg <robin.rosenberg.lists@dewire.com>,
	"Shawn O. Pearce" <spearce@spearce.org>
Cc: git <git@vger.kernel.org>
Subject: [PATCH JGIT] Inefficient use of keySet iterator instead of entrySet iterator
Date: Thu, 19 Mar 2009 10:17:56 +0100	[thread overview]
Message-ID: <49C20DC4.1090600@gmail.com> (raw)

>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 <yann.simon.fr@gmail.com>
---
 .../src/org/spearce/jgit/lib/ObjectIdMap.java      |    5 +++--
 .../src/org/spearce/jgit/transport/AmazonS3.java   |    5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectIdMap.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectIdMap.java
index d3c7f1d..10feaf9 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectIdMap.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectIdMap.java
@@ -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);
 		}
 	}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/AmazonS3.java b/org.spearce.jgit/src/org/spearce/jgit/transport/AmazonS3.java
index 59337f8..3d8bdca 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/AmazonS3.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/AmazonS3.java
@@ -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();
-- 
1.6.1.2

                 reply	other threads:[~2009-03-19  9:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49C20DC4.1090600@gmail.com \
    --to=yann.simon.fr@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg.lists@dewire.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.