From 351ab5fbadd933da771a1bd008eff3960360cfc5 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sat, 28 Oct 2023 21:49:50 +0200 Subject: LibC: Skip using cache if length requested is longer than the cache block This avoid a bunch of extra systemcalls that would have to be made to read each portion into a cache block. --- userland/libc/stdio/stdin.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'userland/libc') diff --git a/userland/libc/stdio/stdin.c b/userland/libc/stdio/stdin.c index e84ea7e..98189e2 100644 --- a/userland/libc/stdio/stdin.c +++ b/userland/libc/stdio/stdin.c @@ -26,6 +26,14 @@ size_t non_cache_read_fd(FILE *f, unsigned char *s, size_t l) { size_t read_fd(FILE *f, unsigned char *s, size_t l) { if (0 == l) return 0; + + // Skip using cache if the length being requested if longer than or + // equal to the cache block size. This avoids doing a bunch of extra + // syscalls + if (l >= 4096) { + return non_cache_read_fd(f, s, l); + } + if (!f->read_buffer) { f->read_buffer = malloc(4096); f->read_buffer_stored = 0; -- cgit v1.2.3