Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
wrap_map: Add capacity to vectors for better performance (#31055)
Remco Smits44fbe27d31e6
diff --git a/crates/editor/src/display_map/wrap_map.rs b/crates/editor/src/display_map/wrap_map.rsindex f6aad19e1b7..ca7ee056c41 100644--- a/crates/editor/src/display_map/wrap_map.rs+++ b/crates/editor/src/display_map/wrap_map.rs@@ -411,7 +411,7 @@ impl WrapSnapshot {}let mut tab_edits_iter = tab_edits.iter().peekable();- let mut row_edits = Vec::new();+ let mut row_edits = Vec::with_capacity(tab_edits.len());while let Some(edit) = tab_edits_iter.next() {let mut row_edit = RowEdit {old_rows: edit.old.start.row()..edit.old.end.row() + 1,@@ -561,7 +561,7 @@ impl WrapSnapshot {}fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &WrapSnapshot) -> Patch<u32> {- let mut wrap_edits = Vec::new();+ let mut wrap_edits = Vec::with_capacity(tab_edits.len());let mut old_cursor = self.transforms.cursor::<TransformSummary>(&());let mut new_cursor = new_snapshot.transforms.cursor::<TransformSummary>(&());for mut tab_edit in tab_edits.iter().cloned() {