From 01d00d45d8a09e53a0e7f1946dbd75a85d210fc0 Mon Sep 17 00:00:00 2001
From: Matt Ellis <m.t.ellis@gmail.com>
Date: Tue, 3 Sep 2024 13:51:25 +0100
Subject: [PATCH] Add a default size for the digraph string builder

---
 .../kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt  | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt
index e7ee1d30a..bf92c5c0e 100644
--- a/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt
+++ b/vim-engine/src/main/kotlin/com/maddyhome/idea/vim/api/VimDigraphGroupBase.kt
@@ -110,7 +110,9 @@ open class VimDigraphGroupBase() : VimDigraphGroup {
       logger.debug("height=$height")
     }
 
-    val output = buildString {
+    val digraphCount = defaultDigraphs.size / 3
+    val capacity = (digraphCount * columnWidth) + (digraphCount / columnCount)  // Text + newlines
+    val output = buildString(capacity) {
       var column = 0
 
       // We cannot guarantee ordering with the dictionaries, so let's use the defaultDigraphs list