Improve performance by removing the use of an intermediate g_malloc'd

2007-06-14  Ryan Lortie  <desrt@desrt.ca>

	* docs/reference/glib/glib-sections.txt:
	* glib/glib/symbols:
	* glib/gstring.[ch] (g_string_printf_internal): Improve
	performance by removing the use of an intermediate g_malloc'd
	buffer.  Rename to g_string_append_vprintf, document, and expose
	along with g_string_vprintf as new public API (#57693).


svn path=/trunk/; revision=5564
This commit is contained in:
Ryan Lortie 2007-06-15 12:43:54 +00:00 committed by Mathias Hasselmann
parent ed4d216d2b
commit 020af9f1dc
5 changed files with 68 additions and 12 deletions

View File

@ -1,3 +1,12 @@
2007-06-14 Ryan Lortie <desrt@desrt.ca>
* docs/reference/glib/glib-sections.txt:
* glib/glib/symbols:
* glib/gstring.[ch] (g_string_printf_internal): Improve
performance by removing the use of an intermediate g_malloc'd
buffer. Rename to g_string_append_vprintf, document, and expose
along with g_string_vprintf as new public API (#57693).
2007-06-15 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* build, tests/string-test.c, glib/glib.symbols,

View File

@ -2018,6 +2018,8 @@ g_string_sized_new
g_string_assign
g_string_sprintf
g_string_sprintfa
g_string_vprintf
g_string_append_vprintf
g_string_printf
g_string_append_printf
g_string_append

View File

@ -1124,6 +1124,7 @@ g_string_append
g_string_append_len
g_string_append_printf G_GNUC_PRINTF(2,3)
g_string_append_unichar
g_string_append_vprintf
g_string_ascii_down
g_string_ascii_up
g_string_assign
@ -1157,6 +1158,7 @@ g_string_truncate
g_string_down
g_string_up
#endif
g_string_vprintf
#ifdef INCLUDE_INTERNAL_SYMBOLS
/* these are not internal, but we don't want to alias them */
g_string_append_c

View File

@ -1260,17 +1260,54 @@ g_string_up (GString *string)
return string;
}
static void
g_string_append_printf_internal (GString *string,
const gchar *fmt,
va_list args)
/**
* g_string_append_vprintf:
* @string: a #GString.
* @format: the string format. See the printf() documentation.
* @args: the list of arguments to insert in the output.
*
* Appends a formatted string onto the end of a #GString.
* This function is is similar to g_string_append_printf()
* except that the arguments to the format string are passed
* as a va_list.
*
* Since: 2.14
*/
void
g_string_append_vprintf (GString *string,
const gchar *fmt,
va_list args)
{
gchar *buffer;
gint length;
length = g_vasprintf (&buffer, fmt, args);
g_string_append_len (string, buffer, length);
g_free (buffer);
gsize length;
g_return_if_fail (string != NULL);
g_return_if_fail (fmt != NULL);
length = g_printf_string_upper_bound (fmt, args);
g_string_maybe_expand (string, length);
length = g_vsnprintf (string->str + string->len, length, fmt, args);
string->len += length;
}
/**
* g_string_vprintf:
* @string: a #GString.
* @format: the string format. See the printf() documentation.
* @Varargs: the parameters to insert into the format string.
*
* Writes a formatted string into a #GString. This function
* is similar to g_string_printf() except that the arguments to
* the format string are passed as a va_list.
*
* Since: 2.14
*/
void
g_string_vprintf (GString *string,
const gchar *fmt,
va_list args)
{
g_string_truncate (string, 0);
g_string_append_vprintf (string, fmt, args);
}
/**
@ -1310,7 +1347,7 @@ g_string_printf (GString *string,
g_string_truncate (string, 0);
va_start (args, fmt);
g_string_append_printf_internal (string, fmt, args);
g_string_append_vprintf (string, fmt, args);
va_end (args);
}
@ -1346,7 +1383,7 @@ g_string_append_printf (GString *string,
va_list args;
va_start (args, fmt);
g_string_append_printf_internal (string, fmt, args);
g_string_append_vprintf (string, fmt, args);
va_end (args);
}

View File

@ -117,9 +117,15 @@ GString* g_string_erase (GString *string,
gssize len);
GString* g_string_ascii_down (GString *string);
GString* g_string_ascii_up (GString *string);
void g_string_vprintf (GString *string,
const gchar *format,
va_list args);
void g_string_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
void g_string_append_vprintf (GString *string,
const gchar *format,
va_list args);
void g_string_append_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);