glib: use g_strdup() in g_ascii_strdown(),g_ascii_strup()

g_strndup() internally uses strncpy(), while g_strdup() uses memcpy().
Most likely, memcpy() is faster.

Instead of strlen()+g_strndup(), use  g_strdup() as we don't need the
length.
This commit is contained in:
Thomas Haller 2024-01-25 16:02:38 +01:00
parent 96b1298871
commit 6955c25e85

View File

@ -1555,9 +1555,10 @@ g_ascii_strdown (const gchar *str,
g_return_val_if_fail (str != NULL, NULL);
if (len < 0)
len = (gssize) strlen (str);
result = g_strdup (str);
else
result = g_strndup (str, (gsize) len);
result = g_strndup (str, (gsize) len);
for (s = result; *s; s++)
*s = g_ascii_tolower (*s);
@ -1585,9 +1586,10 @@ g_ascii_strup (const gchar *str,
g_return_val_if_fail (str != NULL, NULL);
if (len < 0)
len = (gssize) strlen (str);
result = g_strdup (str);
else
result = g_strndup (str, (gsize) len);
result = g_strndup (str, (gsize) len);
for (s = result; *s; s++)
*s = g_ascii_toupper (*s);