Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MallocSizeOf for cssparser types #399

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ jobs:
features:
-
- --features dummy_match_byte
- --features malloc_size_of
include:
- toolchain: nightly
features: --features bench
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cssparser"
version = "0.34.0"
version = "0.34.1"
authors = ["Simon Sapin <[email protected]>"]

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]
4 changes: 2 additions & 2 deletions src/from_bytes.rs
Original file line number Diff line number Diff line change
@@ -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<E>(
3 changes: 3 additions & 0 deletions src/serializer.rs
Original file line number Diff line number Diff line change
@@ -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(
6 changes: 6 additions & 0 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
@@ -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<Token<'a>, ()> {
if tokenizer.is_eof() {
return Err(());