mirror of
https://github.com/wez/wezterm.git
synced 2024-11-22 13:16:39 +03:00
fix(clippy): Use faster
methods on Iterators
- Use `find` instead of `position(..).next()` - Use `any` instead of `position(..).next().is_some()/.is_none()` - Use `first/next` instead of `get(0)/nth(0)` - Prefer `for` loops over `while let` loops on iterators May improve performance.
This commit is contained in:
parent
1ccc6c9ce0
commit
191aacc7d7
@ -103,8 +103,8 @@ impl BidiRun {
|
||||
impl<'a> Iterator for Iter<'a> {
|
||||
type Item = usize;
|
||||
fn next(&mut self) -> Option<usize> {
|
||||
while let Some(idx) = self.range.next() {
|
||||
if self.removed_by_x9.iter().position(|&i| i == idx).is_some() {
|
||||
for idx in self.range.by_ref() {
|
||||
if self.removed_by_x9.iter().any(|&i| i == idx) {
|
||||
// Skip it
|
||||
continue;
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ impl TextStyle {
|
||||
// Insert our bundled default JetBrainsMono as a fallback
|
||||
// in case their preference doesn't match anything.
|
||||
// But don't add it if it is already their preference.
|
||||
if font.iter().position(|f| *f == default_font).is_none() {
|
||||
if !font.iter().any(|f| *f == default_font) {
|
||||
default_font.is_fallback = true;
|
||||
font.push(default_font);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ impl LocalProcessInfo {
|
||||
Some(LinuxStat {
|
||||
pid,
|
||||
name: name.to_string(),
|
||||
status: fields.get(0)?.to_string(),
|
||||
status: fields.first()?.to_string(),
|
||||
ppid: fields.get(1)?.parse().ok()?,
|
||||
starttime: fields.get(20)?.parse().ok()?,
|
||||
})
|
||||
|
@ -1905,7 +1905,7 @@ impl TerminalState {
|
||||
break;
|
||||
}
|
||||
|
||||
let ch = cell.str().chars().nth(0).unwrap() as u32;
|
||||
let ch = cell.str().chars().next().unwrap() as u32;
|
||||
// debug!("y={} col={} ch={:x} cell={:?}", y + y_origin, col, ch, cell);
|
||||
|
||||
checksum += u16::from(ch as u8);
|
||||
|
@ -552,8 +552,7 @@ impl ParsedFont {
|
||||
};
|
||||
let style = *styles
|
||||
.iter()
|
||||
.filter(|&&style| candidates.iter().any(|&idx| fonts[idx].style == style))
|
||||
.next()?;
|
||||
.find(|&&style| candidates.iter().any(|&idx| fonts[idx].style == style))?;
|
||||
|
||||
// Reduce to matching italics
|
||||
candidates.retain(|&idx| fonts[idx].style == style);
|
||||
|
@ -466,8 +466,8 @@ impl HarfbuzzShaper {
|
||||
cluster_resolver.build(hb_infos, s, &range);
|
||||
log::debug!("cluster_resolver: {cluster_resolver:#?}");
|
||||
|
||||
let mut info_iter = hb_infos.iter().zip(positions.iter()).peekable();
|
||||
while let Some((info, pos)) = info_iter.next() {
|
||||
let info_iter = hb_infos.iter().zip(positions.iter()).peekable();
|
||||
for (info, pos) in info_iter {
|
||||
let cluster_info = match cluster_resolver.get_mut(info.cluster as usize) {
|
||||
Some(i) => i,
|
||||
None => panic!(
|
||||
|
@ -61,10 +61,7 @@ pub struct GlConnection {
|
||||
impl GlConnection {
|
||||
#[allow(dead_code)]
|
||||
pub fn has_extension(&self, wanted: &str) -> bool {
|
||||
self.extensions
|
||||
.split(' ')
|
||||
.find(|&ext| ext == wanted)
|
||||
.is_some()
|
||||
self.extensions.split(' ').any(|ext| ext == wanted)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user