mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Merge branch 'uri-preallocation' into 'main'
guri: Preallocate a buffer for building URIs See merge request GNOME/glib!2637
This commit is contained in:
commit
6399ff04c3
12
glib/guri.c
12
glib/guri.c
@ -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.
|
||||
* It’s 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);
|
||||
|
Loading…
Reference in New Issue
Block a user