From c9987f9488fde97c5f919cd1d1d9453793411e23 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sat, 15 May 2021 11:32:34 +0200 Subject: [PATCH] Optimize `Rope::append` by merging chunks only when they're underflowing --- zed/src/editor/buffer/rope.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zed/src/editor/buffer/rope.rs b/zed/src/editor/buffer/rope.rs index 994022deee..78ed156308 100644 --- a/zed/src/editor/buffer/rope.rs +++ b/zed/src/editor/buffer/rope.rs @@ -26,8 +26,12 @@ impl Rope { let mut chunks = rope.chunks.cursor::<(), ()>(); chunks.next(); if let Some(chunk) = chunks.item() { - self.push(&chunk.0); - chunks.next(); + if self.chunks.last().map_or(false, |c| c.0.len() < CHUNK_BASE) + || chunk.0.len() < CHUNK_BASE + { + self.push(&chunk.0); + chunks.next(); + } } self.chunks.push_tree(chunks.suffix(&()), &());