From 85896214ba2a922c4f6d98a7156eb973f791c42d Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 4 Jun 2023 00:23:06 +0200 Subject: [PATCH] libos: Make File::read_all() read chunked blocks instead of one character at a time This results in a speedup of 0.23s -> 0.13s for Base64 encoding of /bin/ls. --- libos/src/File.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libos/src/File.cpp b/libos/src/File.cpp index 0c8fe70e..33155dbc 100644 --- a/libos/src/File.cpp +++ b/libos/src/File.cpp @@ -154,18 +154,18 @@ namespace os Result File::read_all() { - Vector data; + Buffer data; + + u8 buf[2048]; while (true) { - int c = TRY(getchar()); - if (c == -1) break; - TRY(data.try_append((u8)c)); + usize nread = TRY(raw_read(buf, sizeof(buf))); + TRY(data.append_data(buf, nread)); + if (nread < sizeof(buf)) break; } - Buffer buf; - TRY(buf.append_data(data.data(), data.size())); - return buf; + return data; } Result File::read(Buffer& buf, usize size)