From 1790772482f13aef2b1c629d2a8bf0023c9a5917 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 15 Feb 2025 16:16:39 +1300 Subject: [PATCH 1/2] Implement MallocSizeOf for cssparser types --- .github/workflows/main.yml | 1 + Cargo.toml | 3 ++- src/serializer.rs | 3 +++ src/tokenizer.rs | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b08ddef7..a7be6aec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,7 @@ jobs: features: - - --features dummy_match_byte + - --features malloc_size_of include: - toolchain: nightly features: --features bench diff --git a/Cargo.toml b/Cargo.toml index f783f19f..f4e980fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.34.0" +version = "0.34.1" authors = ["Simon Sapin "] description = "Rust implementation of CSS Syntax Level 3" @@ -25,6 +25,7 @@ dtoa-short = "0.3" itoa = "1.0" phf = { version = "0.11.2", features = ["macros"] } serde = { version = "1.0", features = ["derive"], optional = true } +malloc_size_of = { version = "0.1", default-features = false, optional = true } smallvec = "1.0" [profile.profiling] diff --git a/src/serializer.rs b/src/serializer.rs index 5df73954..6696a622 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -466,6 +466,9 @@ pub enum TokenSerializationType { Other, } +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(TokenSerializationType); + impl TokenSerializationType { /// Return a value that represents the absence of a token, e.g. before the start of the input. #[deprecated( diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 2e86c66a..892d10ae 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -533,6 +533,9 @@ impl<'a> Tokenizer<'a> { #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)] pub struct SourcePosition(pub(crate) usize); +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(SourcePosition); + impl SourcePosition { /// Returns the current byte index in the original input. #[inline] @@ -552,6 +555,9 @@ pub struct SourceLocation { pub column: u32, } +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(SourceLocation); + fn next_token<'a>(tokenizer: &mut Tokenizer<'a>) -> Result, ()> { if tokenizer.is_eof() { return Err(()); From 2a94bb13e7edefc4370b5fba296998b05dd4f27d Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Sat, 15 Feb 2025 16:23:42 +1300 Subject: [PATCH 2/2] Fix clippy lints Signed-off-by: Nico Burns --- src/from_bytes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/from_bytes.rs b/src/from_bytes.rs index 78a56d3e..7d9d2c76 100644 --- a/src/from_bytes.rs +++ b/src/from_bytes.rs @@ -24,9 +24,9 @@ pub trait EncodingSupport { /// /// * `css_bytes`: A byte string. /// * `protocol_encoding`: The encoding label, if any, defined by HTTP or equivalent protocol. -/// (e.g. via the `charset` parameter of the `Content-Type` header.) +/// (e.g. via the `charset` parameter of the `Content-Type` header.) /// * `environment_encoding`: An optional `Encoding` object for the [environment encoding] -/// (https://drafts.csswg.org/css-syntax/#environment-encoding), if any. +/// (https://drafts.csswg.org/css-syntax/#environment-encoding), if any. /// /// Returns the encoding to use. pub fn stylesheet_encoding(