From 176bf93e2ecb3b408a35370f50a0dd0756d8be43 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 29 May 2012 12:52:42 +0200 Subject: [PATCH] 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 file 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, -- 1.7.9.5