+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,
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);
}
/**
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);
}
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);
}
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);