From f30af12bea0d55971dac37d8891bd9717158d73e Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Tue, 10 Dec 2019 13:44:59 -0500 Subject: [PATCH] Add hotpath for BufferedOutStream (#3858) * Add hotpath for BufferedOutStream --- lib/std/io.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/std/io.zig b/lib/std/io.zig index c8635b8551daaec0a114512c6cb88e6e5cae3cfd..312e954a7d242daef5d85ae8aa615dd1dd7d7f0c 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -592,7 +592,16 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr fn writeFn(out_stream: *Stream, bytes: []const u8) Error!void { const self = @fieldParentPtr(Self, "stream", out_stream); - if (bytes.len >= self.buffer.len) { + if (bytes.len == 1) { + // This is not required logic but a shorter path + // for single byte writes + self.buffer[self.index] = bytes[0]; + self.index += 1; + if (self.index == buffer_size) { + try self.flush(); + } + return; + } else if (bytes.len >= self.buffer.len) { try self.flush(); return self.unbuffered_out_stream.write(bytes); } -- 2.54.0