editor: Apply common_prefix_len refactor suggestion (#31957)

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>
This commit is contained in:
Gilles Peiffer 2025-06-03 23:07:14 +02:00 committed by GitHub
parent 27d3da678c
commit b9256dd469
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,