libos: Make File::read_all() read chunked blocks instead of one character at a time
All checks were successful
continuous-integration/drone/push Build is passing

This results in a speedup of 0.23s -> 0.13s for Base64 encoding of /bin/ls.
This commit is contained in:
apio 2023-06-04 00:23:06 +02:00
parent 3283991ec6
commit 85896214ba
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -154,18 +154,18 @@ namespace os
Result<Buffer> File::read_all() Result<Buffer> File::read_all()
{ {
Vector<u8> data; Buffer data;
u8 buf[2048];
while (true) while (true)
{ {
int c = TRY(getchar()); usize nread = TRY(raw_read(buf, sizeof(buf)));
if (c == -1) break; TRY(data.append_data(buf, nread));
TRY(data.try_append((u8)c)); if (nread < sizeof(buf)) break;
} }
Buffer buf; return data;
TRY(buf.append_data(data.data(), data.size()));
return buf;
} }
Result<void> File::read(Buffer& buf, usize size) Result<void> File::read(Buffer& buf, usize size)