summaryrefslogtreecommitdiff
path: root/userland/libc/stdio
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-28 21:49:50 +0200
committerAnton Kling <anton@kling.gg>2023-10-30 21:49:48 +0100
commit351ab5fbadd933da771a1bd008eff3960360cfc5 (patch)
treef1e630b017bdce2677c005b9db261c11c8633133 /userland/libc/stdio
parent4c2e0016a2fdfaccf04431ea7205c09dc73c57f8 (diff)
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.
Diffstat (limited to 'userland/libc/stdio')
-rw-r--r--userland/libc/stdio/stdin.c8
1 files changed, 8 insertions, 0 deletions
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;