terminal: avoid reallocating tabstop storage (#13465)

Avoid redundant tabstop allocation when the current buffer already
satisfies the requested size
This commit is contained in:
Mitchell Hashimoto
2026-07-26 14:43:14 -07:00
committed by GitHub

View File

@@ -140,7 +140,7 @@ pub fn resize(
// What we need in the dynamic size
const size = cols - prealloc_columns;
if (size < self.dynamic_stops.len) {
if (size <= self.dynamic_stops.len) {
self.cols = cols;
return;
}
@@ -221,6 +221,15 @@ test "Tabstops: dynamic allocations" {
try testing.expect(!t.get(5));
}
test "Tabstops: resize to existing capacity does not allocate" {
var backing: [prealloc_columns]Unit = undefined;
var fixed = std.heap.FixedBufferAllocator.init(&backing);
var t: Tabstops = .{};
try t.resize(fixed.allocator(), prealloc_columns * 2);
try t.resize(fixed.allocator(), prealloc_columns * 2);
}
test "Tabstops: interval" {
var t: Tabstops = try init(testing.allocator, 80, 4);
defer t.deinit(testing.allocator);