editor: Apply `common_prefix_len` refactor suggestion (#31957)
Gilles Peiffer
and
João Marcos
created
This adds João's nice suggestion from
https://github.com/zed-industries/zed/pull/31818#discussion_r2118582616.
Release Notes:
- N/A
---------
Co-authored-by: João Marcos <marcospb19@hotmail.com>
Change summary
crates/editor/src/editor.rs | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
Detailed changes
@@ -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,