Refine ibus_keymap_get
authorPeng Huang <shawn.p.huang@gmail.com>
Tue, 2 Feb 2010 00:25:57 +0000 (08:25 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Tue, 2 Feb 2010 00:25:57 +0000 (08:25 +0800)
src/ibuskeymap.c

index b28b240782e637e8e64b0f723342791d9fbe366d..6443f95e83e03914617ee894de51c9b38d78e5d1 100644 (file)
@@ -250,24 +250,25 @@ ibus_keymap_get (const gchar *name)
     }
 
     keymap = (IBusKeymap *) g_hash_table_lookup (keymaps, name);
-    if (keymap != NULL) {
-        return keymap;
-    }
-
-    keymap = g_object_new (IBUS_TYPE_KEYMAP, NULL);
-    g_object_ref_sink (keymap);
-
-    if (!ibus_keymap_load (name, keymap->keymap)) {
-        g_object_unref (keymap);
-        return NULL;
-    }
 
-    ibus_keymap_fill (keymap->keymap);
-    keymap->name = g_strdup (name);
-    g_hash_table_insert (keymaps, g_strdup (keymap->name), g_object_ref (keymap));
+    if (keymap == NULL) {
+        keymap = g_object_new (IBUS_TYPE_KEYMAP, NULL);
+        g_object_ref_sink (keymap);
 
-    g_signal_connect (keymap, "destroy", G_CALLBACK (_keymap_destroy_cb), NULL);
+        if (ibus_keymap_load (name, keymap->keymap)) {
+            ibus_keymap_fill (keymap->keymap);
+            keymap->name = g_strdup (name);
+            g_hash_table_insert (keymaps, g_strdup (keymap->name), g_object_ref (keymap));
 
+            g_signal_connect (keymap, "destroy", G_CALLBACK (_keymap_destroy_cb), NULL);
+        }
+        else {
+            g_object_unref (keymap);
+            keymap = NULL;
+        }
+    }
+    if (keymap != NULL)
+        g_object_ref_sink (keymap);
     return keymap;
 }