From 34c040261580c6f61a0f3e7442eafa2ca0fd296a Mon Sep 17 00:00:00 2001 From: Beldaa Date: Sat, 18 Apr 2026 16:09:10 +0200 Subject: [PATCH] Fix Buffer.GrowBuffer() using wrong variable for allocation size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GrowBuffer() calculated an optimal capacity in ewLength (doubling below 1MB, linear growth above) but then allocated the new array with equiredLength instead, making the growth strategy dead code. This caused O(n) reallocations instead of O(log n), degrading sequential Add/Insert operations from O(n) amortized to O(n²). --- Topten.RichTextKit/Utils/Buffer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Topten.RichTextKit/Utils/Buffer.cs b/Topten.RichTextKit/Utils/Buffer.cs index 9325096..e0b996f 100644 --- a/Topten.RichTextKit/Utils/Buffer.cs +++ b/Topten.RichTextKit/Utils/Buffer.cs @@ -110,7 +110,7 @@ bool GrowBuffer(int requiredLength) newLength = requiredLength; // Allocate new buffer, only copying _length, not Data.Length - var newData = new T[requiredLength]; + var newData = new T[newLength]; Array.Copy(_data, 0, newData, 0, _length); _data = newData;