Merge branch 'uri-preallocation' into 'main'

guri: Preallocate a buffer for building URIs

See merge request GNOME/glib!2637
This commit is contained in:
Philip Withnall 2022-05-05 13:30:31 +00:00
commit 6399ff04c3

View File

@ -1633,9 +1633,17 @@ g_uri_join_internal (GUriFlags flags,
g_return_val_if_fail (host == NULL || (path[0] == '\0' || path[0] == '/'), NULL);
g_return_val_if_fail (host != NULL || (path[0] != '/' || path[1] != '/'), NULL);
str = g_string_new (scheme);
/* Arbitrarily chosen default size which should handle most average length
* URIs. This should avoid a few reallocations of the buffer in most cases.
* Its 1B shorter than a power of two, since GString will add a
* nul-terminator byte. */
str = g_string_sized_new (127);
if (scheme)
g_string_append_c (str, ':');
{
g_string_append (str, scheme);
g_string_append_c (str, ':');
}
if (flags & G_URI_FLAGS_SCHEME_NORMALIZE && scheme && ((host && port != -1) || path[0] == '\0'))
normalized_scheme = g_ascii_strdown (scheme, -1);