telepathy-glib: TpDynamicHandleRepo: factor out ensure_handle_take_normalized_id()

Xavier Claessens xclaesse at kemper.freedesktop.org
Thu Jun 28 04:52:17 PDT 2012


Module: telepathy-glib
Branch: master
Commit: 005b08101e316ac0bdf375f18cc75df7f6990857
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=005b08101e316ac0bdf375f18cc75df7f6990857

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Tue May 29 12:52:42 2012 +0200

TpDynamicHandleRepo: factor out ensure_handle_take_normalized_id()

https://bugs.freedesktop.org/show_bug.cgi?id=50341

---

 telepathy-glib/handle-repo-dynamic.c |   51 +++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/telepathy-glib/handle-repo-dynamic.c b/telepathy-glib/handle-repo-dynamic.c
index e324f44..9bd6513 100644
--- a/telepathy-glib/handle-repo-dynamic.c
+++ b/telepathy-glib/handle-repo-dynamic.c
@@ -469,29 +469,14 @@ dynamic_lookup_handle (TpHandleRepoIface *irepo,
 }
 
 static TpHandle
-dynamic_ensure_handle (TpHandleRepoIface *irepo,
-    const char *id,
-    gpointer context,
-    GError **error)
+ensure_handle_take_normalized_id (TpDynamicHandleRepo *self,
+    gchar *normal_id)
 {
-  TpDynamicHandleRepo *self = TP_DYNAMIC_HANDLE_REPO (irepo);
   TpHandle handle;
   TpHandlePriv *priv;
-  gchar *normal_id = NULL;
 
-  if (context == NULL)
-    context = self->default_normalize_context;
-
-  if (self->normalize_function)
-    {
-      normal_id = (self->normalize_function) (irepo, id, context, error);
-      if (normal_id == NULL)
-        return 0;
-
-      id = normal_id;
-    }
-
-  handle = GPOINTER_TO_UINT (g_hash_table_lookup (self->string_to_handle, id));
+  handle = GPOINTER_TO_UINT (g_hash_table_lookup (self->string_to_handle,
+      normal_id));
 
   if (handle != 0)
     {
@@ -499,9 +484,6 @@ dynamic_ensure_handle (TpHandleRepoIface *irepo,
       return handle;
     }
 
-  if (normal_id == NULL)
-    normal_id = g_strdup (id);
-
   handle = self->handle_to_priv->len;
   g_array_append_val (self->handle_to_priv, empty_priv);
   priv = &g_array_index (self->handle_to_priv, TpHandlePriv, handle);
@@ -513,6 +495,31 @@ dynamic_ensure_handle (TpHandleRepoIface *irepo,
   return handle;
 }
 
+static TpHandle
+dynamic_ensure_handle (TpHandleRepoIface *irepo,
+    const char *id,
+    gpointer context,
+    GError **error)
+{
+  TpDynamicHandleRepo *self = TP_DYNAMIC_HANDLE_REPO (irepo);
+  gchar *normal_id;
+
+  if (context == NULL)
+    context = self->default_normalize_context;
+
+  if (self->normalize_function)
+    {
+      normal_id = (self->normalize_function) (irepo, id, context, error);
+      if (normal_id == NULL)
+        return 0;
+    }
+  else
+    {
+      normal_id = g_strdup (id);
+    }
+
+  return ensure_handle_take_normalized_id (self, normal_id);
+}
 
 static void
 dynamic_set_qdata (TpHandleRepoIface *repo, TpHandle handle,



More information about the telepathy-commits mailing list