Module byte_set
Expand description
const builders for [bool; 256] byte-set lookup tables.
A lookup table turns a byte-class predicate into a single branchless
load, which beats a match / compare-chain on hot per-byte paths (URI
validation, HTML tokenizing, …) and is deterministic across compilers.
Build the table once at const time, then index it by byte as usize.
Reach for a table only for irregular byte sets on a hot path: a simple
range such as b < 0x80 is one compare and should stay a comparison.
Functions§
- set_
ascii_ alpha - Mark the ASCII alpha bytes (
A-Z,a-z) astrue. - set_
ascii_ alphanum - Mark the ASCII alphanumeric bytes (
0-9,A-Z,a-z) astrue. - set_
each - Mark every byte present in
bytesastrue. - set_
range - Mark every byte in the half-open range
[lo, hi_exclusive)astrue.