mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-06 09:26:17 +01:00
gio/gdatainputstream: use memchr() when possible
Scanning for stop chars can require looking through a considerable amount of input data. In the case there is a single stop character, use memchr() which can be optimized by the compiler to look at word size or greater amounts of data at a time.
This commit is contained in:
parent
17124abc7e
commit
e7e5ddd2ae
@ -870,13 +870,26 @@ scan_for_chars (GDataInputStream *stream,
|
||||
end = available;
|
||||
peeked = end - start;
|
||||
|
||||
for (i = 0; checked < available && i < peeked; i++)
|
||||
/* For single-char case such as \0, defer to memchr which can
|
||||
* take advantage of simd/etc.
|
||||
*/
|
||||
if (stop_chars_len == 1)
|
||||
{
|
||||
for (stop_char = stop_chars; stop_char != stop_end; stop_char++)
|
||||
{
|
||||
if (buffer[i] == *stop_char)
|
||||
return (start + i);
|
||||
}
|
||||
const char *p = memchr (buffer, stop_chars[0], peeked);
|
||||
|
||||
if (p != NULL)
|
||||
return start + (p - buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; checked < available && i < peeked; i++)
|
||||
{
|
||||
for (stop_char = stop_chars; stop_char != stop_end; stop_char++)
|
||||
{
|
||||
if (buffer[i] == *stop_char)
|
||||
return (start + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checked = end;
|
||||
|
Loading…
Reference in New Issue
Block a user