mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-31 04:39:01 +00:00
terminal: avoid reallocating tabstop storage (#13465)
Avoid redundant tabstop allocation when the current buffer already satisfies the requested size
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user