Optimize the common cases (init == NULL or init == "") a bit. replace uses

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)
This commit is contained in:
Matthias Clasen 2003-03-30 22:02:20 +00:00 committed by Matthias Clasen
parent cb0e4de11c
commit 6710fd6e06
15 changed files with 72 additions and 23 deletions

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -1,5 +1,12 @@
2003-03-30 Matthias Clasen <maclas@gmx.de> 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 * glib/gutf8.c (UNICODE_VALID): Update to Unicode 3.1 and optimize
a bit. (#107427, Noah Lewitt) a bit. (#107427, Noah Lewitt)

View File

@ -335,7 +335,7 @@ unescape_text (GMarkupParseContext *context,
UnescapeState state; UnescapeState state;
const gchar *start; const gchar *start;
str = g_string_new (""); str = g_string_new (NULL);
state = USTATE_INSIDE_TEXT; state = USTATE_INSIDE_TEXT;
p = text; p = text;
@ -681,7 +681,7 @@ add_to_partial (GMarkupParseContext *context,
const gchar *text_end) const gchar *text_end)
{ {
if (context->partial_chunk == NULL) if (context->partial_chunk == NULL)
context->partial_chunk = g_string_new (""); context->partial_chunk = g_string_new (NULL);
if (text_start != text_end) if (text_start != text_end)
g_string_append_len (context->partial_chunk, text_start, g_string_append_len (context->partial_chunk, text_start,
@ -1821,7 +1821,7 @@ g_markup_escape_text (const gchar *text,
if (length < 0) if (length < 0)
length = strlen (text); length = strlen (text);
str = g_string_new (""); str = g_string_new (NULL);
append_escaped_text (str, text, length); append_escaped_text (str, text, length);
return g_string_free (str, FALSE); return g_string_free (str, FALSE);

View File

@ -767,7 +767,7 @@ g_log_default_handler (const gchar *log_domain,
fd = mklevel_prefix (level_prefix, log_level); fd = mklevel_prefix (level_prefix, log_level);
gstring = g_string_new (""); gstring = g_string_new (NULL);
if (log_level & ALERT_LEVELS) if (log_level & ALERT_LEVELS)
g_string_append (gstring, "\n"); g_string_append (gstring, "\n");
if (!log_domain) if (!log_domain)

View File

@ -1267,7 +1267,7 @@ g_scanner_get_token_ll (GScanner *scanner,
g_scanner_get_char (scanner, line_p, position_p); g_scanner_get_char (scanner, line_p, position_p);
token = G_TOKEN_COMMENT_MULTI; token = G_TOKEN_COMMENT_MULTI;
in_comment_multi = TRUE; 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) while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
{ {
if (ch == '*' && g_scanner_peek_next_char (scanner) == '/') if (ch == '*' && g_scanner_peek_next_char (scanner) == '/')
@ -1287,7 +1287,7 @@ g_scanner_get_token_ll (GScanner *scanner,
goto default_case; goto default_case;
token = G_TOKEN_STRING; token = G_TOKEN_STRING;
in_string_sq = TRUE; 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) while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
{ {
if (ch == '\'') if (ch == '\'')
@ -1306,7 +1306,7 @@ g_scanner_get_token_ll (GScanner *scanner,
goto default_case; goto default_case;
token = G_TOKEN_STRING; token = G_TOKEN_STRING;
in_string_dq = TRUE; 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) while ((ch = g_scanner_get_char (scanner, line_p, position_p)) != 0)
{ {
if (ch == '"') if (ch == '"')
@ -1612,7 +1612,7 @@ g_scanner_get_token_ll (GScanner *scanner,
{ {
token = G_TOKEN_COMMENT_SINGLE; token = G_TOKEN_COMMENT_SINGLE;
in_comment_single = TRUE; in_comment_single = TRUE;
gstring = g_string_new (""); gstring = g_string_new (NULL);
ch = g_scanner_get_char (scanner, line_p, position_p); ch = g_scanner_get_char (scanner, line_p, position_p);
while (ch != 0) while (ch != 0)
{ {
@ -1637,7 +1637,7 @@ g_scanner_get_token_ll (GScanner *scanner,
g_scanner_peek_next_char (scanner))) g_scanner_peek_next_char (scanner)))
{ {
token = G_TOKEN_IDENTIFIER; token = G_TOKEN_IDENTIFIER;
gstring = g_string_new (""); gstring = g_string_new (NULL);
gstring = g_string_append_c (gstring, ch); gstring = g_string_append_c (gstring, ch);
do do
{ {

View File

@ -258,7 +258,7 @@ g_shell_unquote (const gchar *quoted_string,
start = unquoted; start = unquoted;
end = unquoted; end = unquoted;
retval = g_string_new (""); retval = g_string_new (NULL);
/* The loop allows cases such as /* The loop allows cases such as
* "foo"blah blah'bar'woo foo"baz"la la la\'\''foo' * "foo"blah blah'bar'woo foo"baz"la la la\'\''foo'
@ -390,7 +390,7 @@ static inline void
ensure_token (GString **token) ensure_token (GString **token)
{ {
if (*token == NULL) if (*token == NULL)
*token = g_string_new (""); *token = g_string_new (NULL);
} }
static void static void

View File

@ -37,7 +37,7 @@ write_err_and_exit (gint fd,
if (debug) if (debug)
{ {
debugstring = g_string_new (""); debugstring = g_string_new (NULL);
g_string_append (debugstring, g_string_append (debugstring,
g_strdup_printf ("writing error code %d and errno %d", g_strdup_printf ("writing error code %d and errno %d",
msg, en)); msg, en));
@ -82,7 +82,7 @@ WinMain (struct HINSTANCE__ *hInstance,
if (debug) if (debug)
{ {
debugstring = g_string_new (""); debugstring = g_string_new (NULL);
g_string_append (debugstring, g_string_append (debugstring,
g_strdup_printf ("g-spawn-win32-helper: " g_strdup_printf ("g-spawn-win32-helper: "
@ -212,7 +212,7 @@ WinMain (struct HINSTANCE__ *hInstance,
if (debug) if (debug)
{ {
debugstring = g_string_new (""); debugstring = g_string_new (NULL);
g_string_append (debugstring, g_string_append (debugstring,
g_strdup_printf ("calling %s %s mode=%s argv: ", g_strdup_printf ("calling %s %s mode=%s argv: ",
(__argv[ARG_USE_PATH][0] == 'y' ? (__argv[ARG_USE_PATH][0] == 'y' ?
@ -237,7 +237,7 @@ WinMain (struct HINSTANCE__ *hInstance,
if (debug) if (debug)
{ {
debugstring = g_string_new (""); debugstring = g_string_new (NULL);
g_string_append (debugstring, g_string_append (debugstring,
g_strdup_printf ("%s returned %#x", g_strdup_printf ("%s returned %#x",
(__argv[ARG_USE_PATH][0] == 'y' ? (__argv[ARG_USE_PATH][0] == 'y' ?

View File

@ -361,7 +361,7 @@ g_spawn_sync (const gchar *working_directory,
if (outpipe >= 0) if (outpipe >= 0)
{ {
outstr = g_string_new (""); outstr = g_string_new (NULL);
outchannel = g_io_channel_win32_new_fd (outpipe); outchannel = g_io_channel_win32_new_fd (outpipe);
g_io_channel_set_encoding (outchannel, NULL, NULL); g_io_channel_set_encoding (outchannel, NULL, NULL);
g_io_channel_win32_make_pollfd (outchannel, g_io_channel_win32_make_pollfd (outchannel,
@ -371,7 +371,7 @@ g_spawn_sync (const gchar *working_directory,
if (errpipe >= 0) if (errpipe >= 0)
{ {
errstr = g_string_new (""); errstr = g_string_new (NULL);
errchannel = g_io_channel_win32_new_fd (errpipe); errchannel = g_io_channel_win32_new_fd (errpipe);
g_io_channel_set_encoding (errchannel, NULL, NULL); g_io_channel_set_encoding (errchannel, NULL, NULL);
g_io_channel_win32_make_pollfd (errchannel, g_io_channel_win32_make_pollfd (errchannel,

View File

@ -263,12 +263,12 @@ g_spawn_sync (const gchar *working_directory,
if (outpipe >= 0) if (outpipe >= 0)
{ {
outstr = g_string_new (""); outstr = g_string_new (NULL);
} }
if (errpipe >= 0) if (errpipe >= 0)
{ {
errstr = g_string_new (""); errstr = g_string_new (NULL);
} }
/* Read data until we get EOF on both pipes. */ /* Read data until we get EOF on both pipes. */

View File

@ -235,10 +235,17 @@ g_string_new (const gchar *init)
{ {
GString *string; 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;
if (init) len = strlen (init);
g_string_append (string, init); string = g_string_sized_new (len + 2);
g_string_append_len (string, init, len);
}
return string; return string;
} }

View File

@ -210,7 +210,7 @@ value_transform_flags_string (const GValue *src_value,
if (flags_value) if (flags_value)
{ {
GString *gstring = g_string_new (""); GString *gstring = g_string_new (NULL);
guint v_flags = src_value->data[0].v_uint; guint v_flags = src_value->data[0].v_uint;
do do