Optimize the common cases (init == NULL or init == "") a bit. replace uses
authorMatthias Clasen <maclas@gmx.de>
Sun, 30 Mar 2003 22:02:20 +0000 (22:02 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Sun, 30 Mar 2003 22:02:20 +0000 (22:02 +0000)
2003-03-30  Matthias Clasen  <maclas@gmx.de>

* glib/gstring.c (g_string_new): Optimize the common cases
(init == NULL or init == "") a bit.
* glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
glib/gspawn.c, gobject/gvaluetransform.c: replace uses of
g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)

15 files changed:
ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gmarkup.c
glib/gmessages.c
glib/gscanner.c
glib/gshell.c
glib/gspawn-win32-helper.c
glib/gspawn-win32.c
glib/gspawn.c
glib/gstring.c
gobject/gvaluetransform.c

index 93e1397..f885529 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index 93e1397..f885529 100644 (file)
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index 93e1397..f885529 100644 (file)
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index 93e1397..f885529 100644 (file)
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index 93e1397..f885529 100644 (file)
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index 93e1397..f885529 100644 (file)
@@ -1,5 +1,12 @@
 2003-03-30  Matthias Clasen  <maclas@gmx.de>
 
+       * glib/gstring.c (g_string_new): Optimize the common cases 
+       (init == NULL or init == "") a bit.
+       * glib/gmarkup.c, glib/gmessages.c, glib/gscanner.c,
+       glib/gshell.c, glib/gspawn-win32-helper.c, glib/gspawn-win32.c,
+       glib/gspawn.c, gobject/gvaluetransform.c: replace uses of 
+       g_string_new ("") by g_string_new (NULL).  (#106973, Morten Welinder)
+
        * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
        a bit.  (#107427, Noah Lewitt)
 
index a45952e..ea86cef 100644 (file)
@@ -335,7 +335,7 @@ unescape_text (GMarkupParseContext *context,
   UnescapeState state;
   const gchar *start;
 
-  str = g_string_new ("");
+  str = g_string_new (NULL);
 
   state = USTATE_INSIDE_TEXT;
   p = text;
@@ -681,7 +681,7 @@ add_to_partial (GMarkupParseContext *context,
                 const gchar         *text_end)
 {
   if (context->partial_chunk == NULL)
-    context->partial_chunk = g_string_new ("");
+    context->partial_chunk = g_string_new (NULL);
 
   if (text_start != text_end)
     g_string_append_len (context->partial_chunk, text_start,
@@ -1821,7 +1821,7 @@ g_markup_escape_text (const gchar *text,
   if (length < 0)
     length = strlen (text);
 
-  str = g_string_new ("");
+  str = g_string_new (NULL);
   append_escaped_text (str, text, length);
 
   return g_string_free (str, FALSE);
index 4f0064c..c593c8c 100644 (file)
@@ -767,7 +767,7 @@ g_log_default_handler (const gchar   *log_domain,
 
   fd = mklevel_prefix (level_prefix, log_level);
 
-  gstring = g_string_new ("");
+  gstring = g_string_new (NULL);
   if (log_level & ALERT_LEVELS)
     g_string_append (gstring, "\n");
   if (!log_domain)
index 632a3eb..a6fef9c 100644 (file)
@@ -1267,7 +1267,7 @@ g_scanner_get_token_ll    (GScanner       *scanner,
          g_scanner_get_char (scanner, line_p, position_p);
          token = G_TOKEN_COMMENT_MULTI;
          in_comment_multi = TRUE;
-         gstring = g_string_new ("");
+         gstring = g_string_new (NULL);
          while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
            {
              if (ch == '*' && g_scanner_peek_next_char (scanner) == '/')
@@ -1287,7 +1287,7 @@ g_scanner_get_token_ll    (GScanner       *scanner,
            goto default_case;
          token = G_TOKEN_STRING;
          in_string_sq = TRUE;
-         gstring = g_string_new ("");
+         gstring = g_string_new (NULL);
          while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
            {
              if (ch == '\'')
@@ -1306,7 +1306,7 @@ g_scanner_get_token_ll    (GScanner       *scanner,
            goto default_case;
          token = G_TOKEN_STRING;
          in_string_dq = TRUE;
-         gstring = g_string_new ("");
+         gstring = g_string_new (NULL);
          while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
            {
              if (ch == '"')
@@ -1612,7 +1612,7 @@ g_scanner_get_token_ll    (GScanner       *scanner,
            {
              token = G_TOKEN_COMMENT_SINGLE;
              in_comment_single = TRUE;
-             gstring = g_string_new ("");
+             gstring = g_string_new (NULL);
              ch = g_scanner_get_char (scanner, line_p, position_p);
              while (ch != 0)
                {
@@ -1637,7 +1637,7 @@ g_scanner_get_token_ll    (GScanner       *scanner,
                          g_scanner_peek_next_char (scanner)))
                {
                  token = G_TOKEN_IDENTIFIER;
-                 gstring = g_string_new ("");
+                 gstring = g_string_new (NULL);
                  gstring = g_string_append_c (gstring, ch);
                  do
                    {
index b6e5b52..9cc49c8 100644 (file)
@@ -258,7 +258,7 @@ g_shell_unquote (const gchar *quoted_string,
 
   start = unquoted;
   end = unquoted;
-  retval = g_string_new ("");
+  retval = g_string_new (NULL);
 
   /* The loop allows cases such as
    * "foo"blah blah'bar'woo foo"baz"la la la\'\''foo'
@@ -390,7 +390,7 @@ static inline void
 ensure_token (GString **token)
 {
   if (*token == NULL)
-    *token = g_string_new ("");
+    *token = g_string_new (NULL);
 }
 
 static void
index 9f9af68..0679031 100644 (file)
@@ -37,7 +37,7 @@ write_err_and_exit (gint fd,
   
   if (debug)
     {
-      debugstring = g_string_new ("");
+      debugstring = g_string_new (NULL);
       g_string_append (debugstring,
                       g_strdup_printf ("writing error code %d and errno %d",
                                        msg, en));
@@ -82,7 +82,7 @@ WinMain (struct HINSTANCE__ *hInstance,
 
   if (debug)
     {
-      debugstring = g_string_new ("");
+      debugstring = g_string_new (NULL);
 
       g_string_append (debugstring,
                       g_strdup_printf ("g-spawn-win32-helper: "
@@ -212,7 +212,7 @@ WinMain (struct HINSTANCE__ *hInstance,
 
   if (debug)
     {
-      debugstring = g_string_new ("");
+      debugstring = g_string_new (NULL);
       g_string_append (debugstring,
                       g_strdup_printf ("calling %s %s mode=%s argv: ",
                                        (__argv[ARG_USE_PATH][0] == 'y' ?
@@ -237,7 +237,7 @@ WinMain (struct HINSTANCE__ *hInstance,
 
   if (debug)
     {
-      debugstring = g_string_new ("");
+      debugstring = g_string_new (NULL);
       g_string_append (debugstring,
                       g_strdup_printf ("%s returned %#x",
                                        (__argv[ARG_USE_PATH][0] == 'y' ?
index 66cfe53..7fd61bb 100644 (file)
@@ -361,7 +361,7 @@ g_spawn_sync (const gchar          *working_directory,
 
   if (outpipe >= 0)
     {
-      outstr = g_string_new ("");
+      outstr = g_string_new (NULL);
       outchannel = g_io_channel_win32_new_fd (outpipe);
       g_io_channel_set_encoding (outchannel, NULL, NULL);
       g_io_channel_win32_make_pollfd (outchannel,
@@ -371,7 +371,7 @@ g_spawn_sync (const gchar          *working_directory,
       
   if (errpipe >= 0)
     {
-      errstr = g_string_new ("");
+      errstr = g_string_new (NULL);
       errchannel = g_io_channel_win32_new_fd (errpipe);
       g_io_channel_set_encoding (errchannel, NULL, NULL);
       g_io_channel_win32_make_pollfd (errchannel,
index be31eed..2af786d 100644 (file)
@@ -263,12 +263,12 @@ g_spawn_sync (const gchar          *working_directory,
 
   if (outpipe >= 0)
     {
-      outstr = g_string_new ("");
+      outstr = g_string_new (NULL);
     }
       
   if (errpipe >= 0)
     {
-      errstr = g_string_new ("");
+      errstr = g_string_new (NULL);
     }
 
   /* Read data until we get EOF on both pipes. */
index 4321496..fb93591 100644 (file)
@@ -235,10 +235,17 @@ g_string_new (const gchar *init)
 {
   GString *string;
 
-  string = g_string_sized_new (init ? strlen (init) + 2 : 2);
+  if (init == NULL || *init == '\0')
+    string = g_string_sized_new (2);
+  else 
+    {
+      gint len;
+
+      len = strlen (init);
+      string = g_string_sized_new (len + 2);
 
-  if (init)
-    g_string_append (string, init);
+      g_string_append_len (string, init, len);
+    }
 
   return string;
 }
index 917d8e9..20e473e 100644 (file)
@@ -210,7 +210,7 @@ value_transform_flags_string (const GValue *src_value,
   
   if (flags_value)
     {
-      GString *gstring = g_string_new ("");
+      GString *gstring = g_string_new (NULL);
       guint v_flags = src_value->data[0].v_uint;
       
       do