Skip to content

Commit 5f517e7

Browse files
committed
Invert match_byte feature flag
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent 8fc7a5c commit 5f517e7

4 files changed

Lines changed: 40 additions & 16 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ inherits = "release"
3333
debug = true
3434

3535
[features]
36+
default = ["fast_match_byte"]
3637
bench = []
37-
dummy_match_byte = []
38+
fast_match_byte = []
3839
# Useful for skipping tests when execution is slow, e.g., under miri
3940
skip_long_tests = []
4041

src/lib.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,39 @@ pub use crate::serializer::{serialize_identifier, serialize_name, serialize_stri
8484
pub use crate::serializer::{CssStringWriter, ToCss, TokenSerializationType};
8585
pub use crate::tokenizer::{SourceLocation, SourcePosition, Token};
8686
pub use crate::unicode_range::UnicodeRange;
87-
pub use cssparser_macros::*;
87+
pub use cssparser_macros::_cssparser_internal_max_len;
88+
89+
#[cfg(feature = "fast_match_byte")]
90+
pub use cssparser_macros::match_byte;
91+
92+
#[cfg(not(feature = "fast_match_byte"))]
93+
#[macro_use]
94+
mod mac {
95+
/// Expand a TokenStream corresponding to the `match_byte` macro.
96+
///
97+
/// ## Example
98+
///
99+
/// ```rust,ignore
100+
/// match_byte! { tokenizer.next_byte_unchecked(),
101+
/// b'a'..b'z' => { ... }
102+
/// b'0'..b'9' => { ... }
103+
/// b'\n' | b'\\' => { ... }
104+
/// foo => { ... }
105+
/// }
106+
/// ```
107+
///
108+
#[macro_export]
109+
macro_rules! match_byte {
110+
($value:expr, $($rest:tt)* ) => {
111+
match $value {
112+
$(
113+
$rest
114+
)+
115+
}
116+
};
117+
}
118+
}
119+
88120
#[doc(hidden)]
89121
pub use phf as _cssparser_internal_phf;
90122

src/serializer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use crate::match_byte;
65
use std::fmt::{self, Write};
76
use std::str;
87

8+
#[cfg(feature = "fast_match_byte")]
9+
pub use crate::match_byte;
10+
911
use super::Token;
1012

1113
/// Trait for things the can serialize themselves in CSS syntax.

src/tokenizer.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,8 @@ use crate::parser::{ArbitrarySubstitutionFunctions, ParserState};
1010
use std::char;
1111
use std::ops::Range;
1212

13-
#[cfg(not(feature = "dummy_match_byte"))]
14-
use cssparser_macros::match_byte;
15-
16-
#[cfg(feature = "dummy_match_byte")]
17-
macro_rules! match_byte {
18-
($value:expr, $($rest:tt)* ) => {
19-
match $value {
20-
$(
21-
$rest
22-
)+
23-
}
24-
};
25-
}
13+
#[cfg(feature = "fast_match_byte")]
14+
pub use crate::match_byte;
2615

2716
/// One of the pieces the CSS input is broken into.
2817
///

0 commit comments

Comments
 (0)