mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
Merge branch 'data-input-stream-optimisation' into 'main'
gdatainputstream: Use memchr() for the multi-stop-char case too See merge request GNOME/glib!4352
This commit is contained in:
commit
85b53d6317
@ -861,11 +861,8 @@ scan_for_chars (GDataInputStream *stream,
|
|||||||
gsize start, end, peeked;
|
gsize start, end, peeked;
|
||||||
gsize i;
|
gsize i;
|
||||||
gsize available, checked;
|
gsize available, checked;
|
||||||
const char *stop_char;
|
|
||||||
const char *stop_end;
|
|
||||||
|
|
||||||
bstream = G_BUFFERED_INPUT_STREAM (stream);
|
bstream = G_BUFFERED_INPUT_STREAM (stream);
|
||||||
stop_end = stop_chars + stop_chars_len;
|
|
||||||
|
|
||||||
checked = *checked_out;
|
checked = *checked_out;
|
||||||
|
|
||||||
@ -874,8 +871,8 @@ scan_for_chars (GDataInputStream *stream,
|
|||||||
end = available;
|
end = available;
|
||||||
peeked = end - start;
|
peeked = end - start;
|
||||||
|
|
||||||
/* For single-char case such as \0, defer to memchr which can
|
/* For single-char case such as \0, defer the entire operation to memchr which
|
||||||
* take advantage of simd/etc.
|
* can take advantage of simd/etc.
|
||||||
*/
|
*/
|
||||||
if (stop_chars_len == 1)
|
if (stop_chars_len == 1)
|
||||||
{
|
{
|
||||||
@ -888,11 +885,13 @@ scan_for_chars (GDataInputStream *stream,
|
|||||||
{
|
{
|
||||||
for (i = 0; checked < available && i < peeked; i++)
|
for (i = 0; checked < available && i < peeked; i++)
|
||||||
{
|
{
|
||||||
for (stop_char = stop_chars; stop_char != stop_end; stop_char++)
|
/* We can use memchr() the other way round. Less fast than the
|
||||||
{
|
* single-char case above, but still faster than doing our own inner
|
||||||
if (buffer[i] == *stop_char)
|
* loop. */
|
||||||
return (start + i);
|
const char *p = memchr (stop_chars, buffer[i], stop_chars_len);
|
||||||
}
|
|
||||||
|
if (p != NULL)
|
||||||
|
return (start + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ test_read_upto (void)
|
|||||||
const char *data_sep;
|
const char *data_sep;
|
||||||
size_t data_sep_len;
|
size_t data_sep_len;
|
||||||
} vectors[] = {
|
} vectors[] = {
|
||||||
{ 10, " part1 # part2 $ part3 \0 part4 ", 32, 7, "#$\0^", 4 },
|
{ 10, " part1 # part2 $ part3 \0 part4 \0", 32, 7, "#$\0^", 4 },
|
||||||
{ 20, "{\"key\": \"value\"}\0", 17, 16, "\0", 1 },
|
{ 20, "{\"key\": \"value\"}\0", 17, 16, "\0", 1 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user