[glib: 5/17] gkeyfile: Eliminate strcmp()s when looking up a group node




commit c29601818fe141ee5bb578fe30a37cecf914a203
Author: Philip Withnall <pwithnall endlessos org>
Date:   Sun Mar 14 13:57:39 2021 +0000

    gkeyfile: Eliminate strcmp()s when looking up a group node
    
    Rather than looking for the group node by comparing each name in the
    linked list of `GKeyFileGroup` instances, look up the `GKeyFileGroup` in
    the hash table, then look up its `GList` node by pointer.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/gkeyfile.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 2fee51324..229f38784 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -4080,17 +4080,12 @@ g_key_file_lookup_group_node (GKeyFile    *key_file,
                              const gchar *group_name)
 {
   GKeyFileGroup *group;
-  GList *tmp;
-
-  for (tmp = key_file->groups; tmp != NULL; tmp = tmp->next)
-    {
-      group = (GKeyFileGroup *) tmp->data;
 
-      if (group && group->name && strcmp (group->name, group_name) == 0)
-        break;
-    }
+  group = g_key_file_lookup_group (key_file, group_name);
+  if (group == NULL)
+    return NULL;
 
-  return tmp;
+  return g_list_find (key_file->groups, group);
 }
 
 static GKeyFileGroup *


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