All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yann Simon <yann.simon.fr@gmail.com>
To: "Shawn O. Pearce" <spearce@spearce.org>,
	Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [PATCH JGIT] use switch to avoid multiple ifs
Date: Sat, 31 Jan 2009 15:25:44 +0100	[thread overview]
Message-ID: <1233411944.8213.2.camel@localhost> (raw)

instead of using multiple ifs that will evaluate an expression x times,
use a switch with cases to evaluate the
expression only one time.
Signed-off-by: Yann Simon <yann.simon.fr@gmail.com>
---
 .../src/org/spearce/jgit/lib/Repository.java       |   29
+++++++++++++------
 1 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index b6efac1..f42bae5 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -389,16 +389,23 @@ public Object mapObject(final ObjectId id, final
String refName) throws IOExcept
 		if (or == null)
 			return null;
 		final byte[] raw = or.getBytes();
-		if (or.getType() == Constants.OBJ_TREE)
+		switch (or.getType()) {
+		case Constants.OBJ_TREE:
 			return makeTree(id, raw);
-		if (or.getType() == Constants.OBJ_COMMIT)
+			
+		case Constants.OBJ_COMMIT:
 			return makeCommit(id, raw);
-		if (or.getType() == Constants.OBJ_TAG)
+			
+		case Constants.OBJ_TAG:
 			return makeTag(id, refName, raw);
-		if (or.getType() == Constants.OBJ_BLOB)
+			
+		case Constants.OBJ_BLOB:
 			return raw;
-		throw new IncorrectObjectTypeException(id,
+			
+		default:
+			throw new IncorrectObjectTypeException(id,
 				"COMMIT nor TREE nor BLOB nor TAG");
+		}
 	}
 
 	/**
@@ -449,12 +456,16 @@ public Tree mapTree(final ObjectId id) throws
IOException {
 		if (or == null)
 			return null;
 		final byte[] raw = or.getBytes();
-		if (Constants.OBJ_TREE == or.getType()) {
+		switch (or.getType()) {
+		case Constants.OBJ_TREE:
 			return new Tree(this, id, raw);
-		}
-		if (Constants.OBJ_COMMIT == or.getType())
+
+		case Constants.OBJ_COMMIT:
 			return mapTree(ObjectId.fromString(raw, 5));
-		throw new IncorrectObjectTypeException(id, Constants.TYPE_TREE);
+			
+		default:
+			throw new IncorrectObjectTypeException(id, Constants.TYPE_TREE);
+		}
 	}
 
 	private Tree makeTree(final ObjectId id, final byte[] raw) throws
IOException {
-- 
1.6.0.6

                 reply	other threads:[~2009-01-31 14:27 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=1233411944.8213.2.camel@localhost \
    --to=yann.simon.fr@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@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.