mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 09:26:17 +01:00
glib/utf8: Use SIMD for g_str_is_ascii()
This moves g_str_is_ascii() from gstrfuncs.c to gutf8.c so that we can reuse the same SIMD code for ASCII validation. On Apple Silicon: Before: 3297 MB/s After: 26146 MB/s
This commit is contained in:
parent
1d3d7336ed
commit
b72650542c
@ -1604,29 +1604,6 @@ g_ascii_strup (const gchar *str,
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_str_is_ascii:
|
||||
* @str: a string
|
||||
*
|
||||
* Determines if a string is pure ASCII. A string is pure ASCII if it
|
||||
* contains no bytes with the high bit set.
|
||||
*
|
||||
* Returns: true if @str is ASCII
|
||||
*
|
||||
* Since: 2.40
|
||||
*/
|
||||
gboolean
|
||||
g_str_is_ascii (const gchar *str)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
for (i = 0; str[i]; i++)
|
||||
if (str[i] & 0x80)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_strdown:
|
||||
* @string: the string to convert
|
||||
|
19
glib/gutf8.c
19
glib/gutf8.c
@ -1886,6 +1886,25 @@ g_utf8_validate_len (const char *str,
|
||||
return max_len == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_str_is_ascii:
|
||||
* @str: a string
|
||||
*
|
||||
* Determines if a string is pure ASCII. A string is pure ASCII if it
|
||||
* contains no bytes with the high bit set.
|
||||
*
|
||||
* Returns: true if @str is ASCII
|
||||
*
|
||||
* Since: 2.40
|
||||
*/
|
||||
gboolean
|
||||
g_str_is_ascii (const gchar *str)
|
||||
{
|
||||
utf8_verify_ascii (&str, NULL);
|
||||
|
||||
return *str == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_unichar_validate:
|
||||
* @ch: a Unicode character
|
||||
|
Loading…
Reference in New Issue
Block a user