Optimize Rope::append by merging chunks only when they're underflowing

This commit is contained in:
Antonio Scandurra 2021-05-15 11:32:34 +02:00
parent 76a74e431e
commit c9987f9488

View file

@ -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(&()), &());