We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b495f2 commit fd6c25dCopy full SHA for fd6c25d
src/msg.zig
@@ -95,8 +95,11 @@ pub const MsgBuffer = struct {
95
96
// check if the current input can fit in MsgBuffer
97
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);
+ // we want to realloc at least:
+ // - 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);
103
// resize the MsgBuffer to fit
104
self.buf = try alloc.realloc(self.buf, max_size);
105
}
0 commit comments