Reduce copying of buffer when reserving

This commit is contained in:
Jasmijn Wellner 2024-12-28 16:19:02 +01:00
parent 0742c8d878
commit 493bc00af8

View File

@ -78,8 +78,10 @@ local function Buffer_newDataReader(data, size)
end
local function Buffer_reserve(additional_size)
while buf_pos + additional_size > buf_size do
buf_size = buf_size * 2
if buf_pos + additional_size > buf_size do
repeat
buf_size = buf_size * 2
until buf_pos + additional_size <= buf_size
local oldbuf = buf
buf = ffi.new("uint8_t[?]", buf_size)
buf_is_writable = true