perf: use `next_back` on `DoubleEndedIterator`

pull/13283/head
Rolo 2025-04-03 14:37:20 -07:00 committed by Michael Davis
parent 1bc45c8b3a
commit 5b72b59448
3 changed files with 4 additions and 3 deletions

View File

@ -65,7 +65,7 @@ pub fn print(s: &str) -> (String, Selection) {
let head_at_beg = iter.next_if_eq(&"|").is_some();
let last_grapheme = |s: &str| {
UnicodeSegmentation::graphemes(s, true)
.last()
.next_back()
.map(String::from)
};

View File

@ -39,7 +39,7 @@ fn workspace_for_uri(uri: lsp::Url) -> WorkspaceFolder {
lsp::WorkspaceFolder {
name: uri
.path_segments()
.and_then(|segments| segments.last())
.and_then(|mut segments| segments.next_back())
.map(|basename| basename.to_string())
.unwrap_or_default(),
uri,

View File

@ -145,7 +145,8 @@ impl Registers {
}
pub fn last<'a>(&'a self, name: char, editor: &'a Editor) -> Option<Cow<'a, str>> {
self.read(name, editor).and_then(|values| values.last())
self.read(name, editor)
.and_then(|mut values| values.next_back())
}
pub fn iter_preview(&self) -> impl Iterator<Item = (char, &str)> {