Skip to main content

Module byte_set

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) as true.
set_ascii_alphanum
Mark the ASCII alphanumeric bytes (0-9, A-Z, a-z) as true.
set_each
Mark every byte present in bytes as true.
set_range
Mark every byte in the half-open range [lo, hi_exclusive) as true.