(i hope that correctry) optimized bytearray:move method

This commit is contained in:
RomanDonw 2026-07-23 17:47:32 +10:00
parent 27bb3015e4
commit 0d641fa82f

View file

@ -185,10 +185,15 @@ local function move(self, fromindex, toindex, size)
fromindex + size - 1 <= self.size and
toindex + size - 1 <= self.size
then
local buff = malloc(size)
FFI.copy(buff, self.bytes + fromindex - 1, size)
FFI.copy(self.bytes + toindex - 1, buff, size)
free(buff)
if toindex >= fromindex and toindex < fromindex + size then
local buff = malloc(size)
FFI.copy(buff, self.bytes + fromindex - 1, size)
FFI.copy(self.bytes + toindex - 1, buff, size)
free(buff)
else
-- убери(-те) это ветвление, если FFI будет производить копирование не побайтово, и оставь(-те) только верхний блок без условия вообще.
FFI.copy(self.bytes + toindex - 1, self.bytes + fromindex - 1, size)
end
end
end