[glib: 10/17] gkeyfile: Move allocation of value until after locale checks have passed




commit 5a38dc79f0161ca94b983702b8b1672e2447872d
Author: Philip Withnall <pwithnall endlessos org>
Date:   Sun Mar 14 14:11:34 2021 +0000

    gkeyfile: Move allocation of value until after locale checks have passed
    
    This avoids allocating a copy of the value in the case that it’s for a
    locale which is uninteresting.
    
    This should speed up parsing of key files with large numbers of
    translations, when only the translations for certain locales are wanted.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/gkeyfile.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
---
diff --git a/glib/gkeyfile.c b/glib/gkeyfile.c
index 50ed5305d..9fd9c6eed 100644
--- a/glib/gkeyfile.c
+++ b/glib/gkeyfile.c
@@ -1420,8 +1420,6 @@ g_key_file_parse_key_value_pair (GKeyFile     *key_file,
         }
     }
 
-  value = g_strndup (value_start, value_len);
-
   /* Is this key a translation? If so, is it one that we care about?
    */
   locale = key_get_locale (key);
@@ -1432,13 +1430,12 @@ g_key_file_parse_key_value_pair (GKeyFile     *key_file,
 
       pair = g_slice_new (GKeyFileKeyValuePair);
       pair->key = g_steal_pointer (&key);
-      pair->value = g_steal_pointer (&value);
+      pair->value = g_strndup (value_start, value_len);
 
       g_key_file_add_key_value_pair (key_file, key_file->current_group, pair);
     }
 
   g_free (key);
-  g_free (value);
   g_free (locale);
 }
 


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