/pidgin/main: 33c8355ead2a: Simpler control flow.

Mark Doliner mark at kingant.net
Mon Jan 21 21:06:07 EST 2013


Changeset: 33c8355ead2ac64de6b2d04f504aa97aa76aa7f6
Author:	 Mark Doliner <mark at kingant.net>
Date:	 2013-01-21 18:06 -0800
Branch:	 release-2.x.y
URL: http://hg.pidgin.im/pidgin/main/rev/33c8355ead2a

Description:

Simpler control flow.

I'm totally fine with multiple "returns" in a single function,
especially when returning early because of error conditions.

diffstat:

 libpurple/imgstore.c |  26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diffs (38 lines):

diff --git a/libpurple/imgstore.c b/libpurple/imgstore.c
--- a/libpurple/imgstore.c
+++ b/libpurple/imgstore.c
@@ -89,20 +89,22 @@ int
 purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename)
 {
 	PurpleStoredImage *img = purple_imgstore_add(data, size, filename);
-	if (img) {
-		/*
-		 * Use the next unused id number.  We do it in a loop on the
-		 * off chance that nextid wraps back around to 0 and the hash
-		 * table still contains entries from the first time around.
-		 */
-		do {
-			img->id = ++nextid;
-		} while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL);
-
-		g_hash_table_insert(imgstore, &(img->id), img);
+	if (!img) {
+		return 0;
 	}
 
-	return (img ? img->id : 0);
+	/*
+	 * Use the next unused id number.  We do it in a loop on the
+	 * off chance that nextid wraps back around to 0 and the hash
+	 * table still contains entries from the first time around.
+	 */
+	do {
+		img->id = ++nextid;
+	} while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL);
+
+	g_hash_table_insert(imgstore, &(img->id), img);
+
+	return img->id;
 }
 
 PurpleStoredImage *purple_imgstore_find_by_id(int id) {



More information about the Commits mailing list