Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
editor: Apply `common_prefix_len` refactor suggestion (#31957)
Gilles Peifferb9256dd469c0
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex b0336c8140b..06cdc68ce6b 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -5550,14 +5550,12 @@ impl Editor {}}- let mut common_prefix_len = 0;- for (a, b) in old_text.chars().zip(new_text.chars()) {- if a == b {- common_prefix_len += a.len_utf8();- } else {- break;- }- }+ let common_prefix_len = old_text+ .chars()+ .zip(new_text.chars())+ .take_while(|(a, b)| a == b)+ .map(|(a, _)| a.len_utf8())+ .sum::<usize>();cx.emit(EditorEvent::InputHandled {utf16_range_to_replace: None,