[geocode-glib] lib: Simplify a few exit paths



commit 15312041ad1a73c1965e033c2821c4be94653ea7
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jul 4 16:35:42 2013 +0200

    lib: Simplify a few exit paths
    
    A lot of duplicated code on error cases when we could reuse most of it.

 geocode-glib/geocode-forward.c  |    9 +++------
 geocode-glib/geocode-ipclient.c |   14 +++-----------
 geocode-glib/geocode-reverse.c  |    9 +++------
 3 files changed, 9 insertions(+), 23 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index fc186b0..c0a68fd 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -344,14 +344,11 @@ on_cache_data_loaded (GObject      *source_forward,
                ret = _geocode_parse_single_result_json (contents, &error);
        g_free (contents);
 
-       if (ret == NULL) {
+       if (ret == NULL)
                g_simple_async_result_take_error (simple, error);
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
-       }
+       else
+               g_simple_async_result_set_op_res_gpointer (simple, ret, NULL);
 
-       g_simple_async_result_set_op_res_gpointer (simple, ret, NULL);
        g_simple_async_result_complete_in_idle (simple);
        g_object_unref (simple);
 }
diff --git a/geocode-glib/geocode-ipclient.c b/geocode-glib/geocode-ipclient.c
index 7c688e9..d2f3570 100644
--- a/geocode-glib/geocode-ipclient.c
+++ b/geocode-glib/geocode-ipclient.c
@@ -257,18 +257,10 @@ query_callback (GObject        *source_forward,
                                          NULL,
                                          &error) == FALSE) {
                 g_simple_async_result_take_error (simple, error);
-                g_simple_async_result_complete_in_idle (simple);
-                g_object_unref (simple);
-                return;
-
-        }
-        if (contents == NULL) {
-                g_simple_async_result_take_error (simple, error);
-                g_simple_async_result_complete_in_idle (simple);
-                g_object_unref (simple);
-                return;
+        } else {
+                g_simple_async_result_set_op_res_gpointer (simple, contents, NULL);
         }
-        g_simple_async_result_set_op_res_gpointer (simple, contents, NULL);
+
         g_simple_async_result_complete_in_idle (simple);
         g_object_unref (simple);
 }
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index ea39833..a86fb00 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -368,14 +368,11 @@ on_cache_data_loaded (GObject      *source_object,
        ret = _geocode_parse_resolve_json (contents, &error);
        g_free (contents);
 
-       if (ret == NULL) {
+       if (ret == NULL)
                g_simple_async_result_take_error (simple, error);
-               g_simple_async_result_complete_in_idle (simple);
-               g_object_unref (simple);
-               return;
-       }
+       else
+               g_simple_async_result_set_op_res_gpointer (simple, ret, NULL);
 
-       g_simple_async_result_set_op_res_gpointer (simple, ret, NULL);
        g_simple_async_result_complete_in_idle (simple);
        g_object_unref (simple);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]