about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2013-08-26 03:29:04 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2013-08-26 03:29:04 +0300
commit982f1174a879d975ad0431a21dcec54efd8a0a50 (patch)
tree3923d953291e181da3ea20a4821b311ab65b9316
parent92763d2e68207b52fbe613058293de0fc8cc7f24 (diff)
downloadprofani-tty-982f1174a879d975ad0431a21dcec54efd8a0a50.tar.gz
refactred autocomplete_remove
-rw-r--r--src/tools/autocomplete.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index afabaed2..77d8c7ae 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -101,30 +101,21 @@ autocomplete_add(Autocomplete ac, const char *item)
 gboolean
 autocomplete_remove(Autocomplete ac, const char * const item)
 {
-    // reset last found if it points to the item to be removed
-    if (ac->last_found != NULL)
-        if (g_strcmp0(ac->last_found->data, item) == 0)
-            ac->last_found = NULL;
+    GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
 
-    if (!ac->items) {
+    if (!curr) {
         return FALSE;
-    } else {
-        GSList *curr = ac->items;
-
-        while(curr) {
-            if (g_strcmp0(curr->data, item) == 0) {
-                void *current_item = curr->data;
-                ac->items = g_slist_remove(ac->items, curr->data);
-                free(current_item);
+    }
 
-                return TRUE;
-            }
+    // reset last found if it points to the item to be removed
+    if (ac->last_found == curr) {
+        ac->last_found = NULL;
+    }
 
-            curr = g_slist_next(curr);
-        }
+    free(curr->data);
+    ac->items = g_slist_delete_link(ac->items, curr);
 
-        return FALSE;
-    }
+    return TRUE;
 }
 
 GSList *