MCPcopy Create free account
hub / github.com/csskit/csskit / fast_parse_integer

Function fast_parse_integer

crates/css_lexer/src/private.rs:868–885  ·  view source on GitHub ↗
(bytes: &[u8], has_sign: bool, num_len: usize)

Source from the content-addressed store, hash-verified

866/// For larger integers, falls back to str::parse.
867#[inline]
868fn fast_parse_integer(bytes: &[u8], has_sign: bool, num_len: usize) -> f32 {
869 let start = if has_sign { 1 } else { 0 };
870 let digit_count = num_len - start;
871 if digit_count <= 9 {
872 let mut value: u32 = 0;
873 let mut i = start;
874 while i < num_len {
875 value = value * 10 + (bytes[i] - b'0') as u32;
876 i += 1;
877 }
878 let fvalue = value as f32;
879 if has_sign && bytes[0] == b'-' { -fvalue } else { fvalue }
880 } else {
881 // Fallback for very large integers (> 9 digits)
882 let str = unsafe { std::str::from_utf8_unchecked(&bytes[0..num_len]) };
883 str.parse::<f32>().unwrap()
884 }
885}
886
887/// Convert raw codepoint to char, handling 0 and surrogates -> REPLACEMENT_CHARACTER
888#[inline]

Callers 1

consume_numeric_tokenMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected