[PATCH] Use memchr in _IO_new_file_xsputn
Bernhard Rosenkränzer
bero@lindev.ch
Thu Jun 11 17:42:05 GMT 2026
Use memchr instead of implementing a bytewise lookup, this should be
slightly faster and more readable
Signed-off-by: Bernhard Rosenkränzer <bero@lindev.ch>
---
libio/fileops.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/libio/fileops.c b/libio/fileops.c
index 9348d7c3a1..a614e7c528 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -1290,15 +1290,11 @@ _IO_new_file_xsputn (FILE *f, const void *data, size_t n)
count = f->_IO_buf_end - f->_IO_write_ptr;
if (count >= n)
{
- const char *p;
- for (p = s + n; p > s; )
+ const char *p = memrchr (s, '\n', n);
+ if (p != NULL)
{
- if (*--p == '\n')
- {
- count = p - s + 1;
- must_flush = 1;
- break;
- }
+ count = p - s + 1;
+ must_flush = 1;
}
}
}
--
2.53.0
More information about the Libc-alpha
mailing list