gio/gdatainputstream.c · 2.84.1 · GNOME / GLib · GitLab (original) (raw)
Oct 15, 2024
e3e936f7
gdatainputstream: Use memchr() for the multi-stop-char case too · e3e936f7
Philip Withnall authored Oct 15, 2024
This is a follow up to commit e7e5ddd2. oss-fuzz found a case where
performance was pathologically bad with a longstop_chars
string.
Since our inner loop in that case was iterating overstop_chars
and
comparing each of them tobuffer[i]
, we can usememchr()
the
opposite way round to in commit e7e5ddd2 to speed that up, usingbuffer[i]
as the needle in astop_chars
haystack.
From some brief testing, this doesn’t impact on the performance of a
more normal use case of having a short (<10 bytes long)stop_chars
. I
was slightly concerned that the function call overhead of calling out tomemchr()
would have an impact there, but apparently not.
Signed-off-by:Philip Withnall <pwithnall@gnome.org>
oss-fuzz#372994443
e3e936f7
gdatainputstream: Use memchr() for the multi-stop-char case too
Philip Withnall authored Oct 15, 2024
This is a follow up to commit e7e5ddd2. oss-fuzz found a case where
performance was pathologically bad with a longstop_chars
string.
Since our inner loop in that case was iterating overstop_chars
and
comparing each of them tobuffer[i]
, we can usememchr()
the
opposite way round to in commit e7e5ddd2 to speed that up, usingbuffer[i]
as the needle in astop_chars
haystack.
From some brief testing, this doesn’t impact on the performance of a
more normal use case of having a short (<10 bytes long)stop_chars
. I
was slightly concerned that the function call overhead of calling out tomemchr()
would have an impact there, but apparently not.
Signed-off-by:Philip Withnall <pwithnall@gnome.org>
oss-fuzz#372994443
Loading