[glib] g_str_to_ascii(): a couple of minor tweaks



commit 8491f03581b6ada1d82f29064c99b604e98c7e09
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Feb 20 18:32:04 2014 -0500

    g_str_to_ascii(): a couple of minor tweaks
    
    Add a precondition guard and use g_string_sized_new() to avoid some
    reallocations.

 glib/gtranslit.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/glib/gtranslit.c b/glib/gtranslit.c
index 3cdfe94..5831456 100644
--- a/glib/gtranslit.c
+++ b/glib/gtranslit.c
@@ -331,6 +331,8 @@ g_str_to_ascii (const gchar *str,
   GString *result;
   guint item_id;
 
+  g_return_val_if_fail (str != NULL, NULL);
+
   if (g_str_is_ascii (str))
     return g_strdup (str);
 
@@ -339,7 +341,7 @@ g_str_to_ascii (const gchar *str,
   else
     item_id = get_default_item_id ();
 
-  result = g_string_new (NULL);
+  result = g_string_sized_new (strlen (str));
 
   while (*str)
     {


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