mirror of
https://github.com/aphrody-labs/opentui.git
synced 2026-10-13 21:08:53 +00:00
OptimizedBuffer.resize reallocated all four cell arrays on every size change. When a reallocation moved, it copied cells that clear() then overwrote. If one reallocation failed, the arrays were left with different lengths while width and height kept the old size, so a failed shrink left a cell array shorter than the buffer's cells. Resize now reuses the arrays while the new cells fit and the capacity stays within half again the cells. Growing past the capacity reserves half of it again, so a buffer that grows a row at a time or alternates sizes reallocates rarely. A larger jump or a shrink takes the exact cells. All four arrays are allocated before any is freed, so a failed resize leaves the buffer unchanged.