Skip to content

Commit fd6c25d

Browse files
msg: improve comments on reallocation
Signed-off-by: Francis Bouvier <[email protected]>
1 parent 4b495f2 commit fd6c25d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/msg.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,11 @@ pub const MsgBuffer = struct {
9595

9696
// check if the current input can fit in MsgBuffer
9797
if (new_pos > self.buf.len) {
98-
// max_size is the max between msg size and current new cursor position
99-
const max_size = @max(self.size, new_pos);
98+
// we want to realloc at least:
99+
// - a size equals to new_pos to fit the entire input
100+
// - a size big enough (ie. current size + starting size)
101+
// to avoid multiple reallocation
102+
const max_size = @max(self.buf.len + self.size, new_pos);
100103
// resize the MsgBuffer to fit
101104
self.buf = try alloc.realloc(self.buf, max_size);
102105
}

0 commit comments

Comments
 (0)