diff --git a/AUTHORS b/AUTHORS index b82fa38b..f7ac007f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,6 +6,7 @@ Ahmed Ibrahim DynamiteC Emre AYDIN +heygsc <1596920983@qq.com> Joshua Thijssen Nicholas Nguyen Niklas Scheerhoorn diff --git a/Cargo.lock b/Cargo.lock index 4705b6b4..ab442cf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -865,6 +865,12 @@ dependencies = [ "libm", ] +[[package]] +name = "cow-utils" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" + [[package]] name = "cpufeatures" version = "0.2.16" @@ -1762,6 +1768,7 @@ version = "0.1.1" dependencies = [ "anyhow", "colors-transform", + "cow-utils", "gosub_interface", "gosub_shared", "itertools 0.14.0", diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000..7ab09c78 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,3 @@ +disallowed-methods = [ + { path = "str::to_ascii_lowercase", reason = "To avoid memory allocation, use `cow_utils::CowUtils::cow_to_ascii_lowercase` instead." }, +] \ No newline at end of file diff --git a/crates/gosub_css3/Cargo.toml b/crates/gosub_css3/Cargo.toml index 09a2c033..d26a48e1 100644 --- a/crates/gosub_css3/Cargo.toml +++ b/crates/gosub_css3/Cargo.toml @@ -20,3 +20,4 @@ serde = { version = "1.0.217", features = ["derive"] } serde_json = "1.0.134" thiserror = "2.0.9" nom = "7.1.3" +cow-utils = "0.1.3" diff --git a/crates/gosub_css3/src/parser/url.rs b/crates/gosub_css3/src/parser/url.rs index 71e40046..7626494b 100644 --- a/crates/gosub_css3/src/parser/url.rs +++ b/crates/gosub_css3/src/parser/url.rs @@ -1,6 +1,7 @@ use crate::node::{Node, NodeType}; use crate::tokenizer::TokenType; use crate::Css3; +use cow_utils::CowUtils; use gosub_shared::errors::CssError; use gosub_shared::errors::CssResult; @@ -11,7 +12,7 @@ impl Css3<'_> { let loc = self.tokenizer.current_location(); let name = self.consume_function()?; - if name.to_ascii_lowercase() != "url" { + if name.cow_to_ascii_lowercase() != "url" { return Err(CssError::with_location( format!("Expected url, got {:?}", name).as_str(), self.tokenizer.current_location(), diff --git a/crates/gosub_css3/src/parser/value.rs b/crates/gosub_css3/src/parser/value.rs index c808ff1e..0a182c03 100644 --- a/crates/gosub_css3/src/parser/value.rs +++ b/crates/gosub_css3/src/parser/value.rs @@ -1,6 +1,7 @@ use crate::node::{Node, NodeType}; use crate::tokenizer::TokenType; use crate::Css3; +use cow_utils::CowUtils; use gosub_shared::errors::CssError; use gosub_shared::errors::CssResult; @@ -74,7 +75,7 @@ impl Css3<'_> { Ok(Some(node)) } TokenType::Function(name) => { - let node = match name.to_ascii_lowercase().as_str() { + let node = match name.cow_to_ascii_lowercase().as_ref() { "calc" => self.parse_calc()?, "url" => { self.tokenizer.reconsume(); diff --git a/crates/gosub_html5/src/parser.rs b/crates/gosub_html5/src/parser.rs index 7168b74a..93a3ca04 100644 --- a/crates/gosub_html5/src/parser.rs +++ b/crates/gosub_html5/src/parser.rs @@ -2616,8 +2616,7 @@ impl<'a, C: HasDocument> Html5Parser<'a, C> { { if ["h1", "h2", "h3", "h4", "h5", "h6"] .iter() - .map(|tag| self.is_in_scope(tag, HTML_NAMESPACE, Scope::Regular)) - .any(|res| res) + .any(|tag| self.is_in_scope(tag, HTML_NAMESPACE, Scope::Regular)) { self.generate_implied_end_tags(Some(name), false);