Fix some clippy issues on the Android build (#35147)

This fixes a variety of clippy issues that show up on the Android build.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-23 16:18:58 +01:00 committed by GitHub
parent 5e5379d3bf
commit f5f5a3f79e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 43 additions and 66 deletions

View file

@ -19,7 +19,7 @@ use crate::{
LocalFontIdentifier, LowercaseFontFamilyName,
};
static FONT_LIST: LazyLock<FontList> = LazyLock::new(|| FontList::new());
static FONT_LIST: LazyLock<FontList> = LazyLock::new(FontList::new);
// Android doesn't provide an API to query system fonts until Android O:
// https://developer.android.com/reference/android/text/FontConfig.html
@ -141,7 +141,7 @@ impl FontList {
let mut result = None;
paths.iter().all(|path| {
result = Self::from_path(path);
!result.is_some()
result.is_none()
});
if result.is_none() {
@ -194,10 +194,7 @@ impl FontList {
}
}
Some(FontList {
families: families,
aliases: aliases,
})
Some(FontList { families, aliases })
}
// Fonts expected to exist in Android devices.
@ -277,24 +274,19 @@ impl FontList {
let mut fonts = Vec::new();
// Parse font variants
for node in familyset {
match node {
Node::Element {
name,
attributes,
children,
} => {
if name.local_name == "font" {
FontList::parse_font(&children, attributes, &mut fonts);
}
},
_ => {},
if let Node::Element {
name,
attributes,
children,
} = node
{
if name.local_name == "font" {
FontList::parse_font(children, attributes, &mut fonts);
}
}
}
out.push(FontFamily {
name: name,
fonts: fonts,
});
out.push(FontFamily { name, fonts });
}
// Parse family and font file names for Androi API < 21
@ -339,10 +331,7 @@ impl FontList {
.collect();
if !fonts.is_empty() {
out.push(FontFamily {
name: name,
fonts: fonts,
})
out.push(FontFamily { name, fonts })
}
}
}
@ -393,11 +382,7 @@ impl FontList {
// Parse optional weight filter
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());
out.push(FontAlias {
from: from,
to: to,
weight: weight,
})
out.push(FontAlias { from, to, weight })
}
fn find_attrib(name: &str, attrs: &[Attribute]) -> Option<String> {
@ -408,7 +393,7 @@ impl FontList {
}
fn text_content(nodes: &[Node]) -> Option<String> {
nodes.get(0).and_then(|child| match child {
nodes.first().and_then(|child| match child {
Node::Text(contents) => Some(contents.trim().into()),
Node::Element { .. } => None,
})

View file

@ -17,7 +17,7 @@ pub(super) enum Node {
pub(super) fn parse(bytes: &[u8]) -> xml::reader::Result<Vec<Node>> {
let mut stack = Vec::new();
let mut nodes = Vec::new();
for result in xml::EventReader::new(&*bytes) {
for result in xml::EventReader::new(bytes) {
match result? {
StartElement {
name, attributes, ..