From 7b293b11c270c086add9bd295ad03dee3bc04e4e Mon Sep 17 00:00:00 2001 From: g4lb Date: Mon, 16 Nov 2026 00:50:54 +0200 Subject: [PATCH 1/2] perf(uri): advance past the scheme in parse_full instead of split_to --- src/uri/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/uri/mod.rs b/src/uri/mod.rs index 0f0b0156..c37f66b2 100644 --- a/src/uri/mod.rs +++ b/src/uri/mod.rs @@ -25,7 +25,7 @@ use crate::byte_str::ByteStr; use std::convert::TryFrom; -use bytes::Bytes; +use bytes::{Buf, Bytes}; use std::error::Error; use std::fmt; @@ -825,16 +825,15 @@ fn parse_full(mut s: Bytes) -> Result { let scheme = match Scheme2::parse(&s[..])? { Scheme2::None => Scheme2::None, Scheme2::Standard(p) => { - // TODO: use truncate - let _ = s.split_to(p.len() + 3); + s.advance(p.len() + 3); Scheme2::Standard(p) } Scheme2::Other(n) => { // Grab the protocol let mut scheme = s.split_to(n + 3); - // Strip ://, TODO: truncate - let _ = scheme.split_off(n); + // Strip :// + scheme.truncate(n); // Allocate the ByteStr let val = unsafe { ByteStr::from_utf8_unchecked(scheme) }; From 7473a2ba033bd8aaa8c588fbfe3f7d9bdd10aaf7 Mon Sep 17 00:00:00 2001 From: g4lb Date: Mon, 16 Nov 2026 00:50:54 +0200 Subject: [PATCH 2/2] perf(uri): skip plain authority bytes with one table lookup --- src/uri/authority.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/uri/authority.rs b/src/uri/authority.rs index c5479cb2..0639fe65 100644 --- a/src/uri/authority.rs +++ b/src/uri/authority.rs @@ -470,6 +470,26 @@ where }) } +// Like URI_CHARS, but bytes that have no special meaning in an authority +// map to PLAIN. +const PLAIN: u8 = 1; + +const fn build_authority_map() -> [u8; 256] { + let mut t = [0; 256]; + let mut i = 0; + while i < 256 { + t[i] = match URI_CHARS[i] { + 0 => 0, + ch @ (b'/' | b'?' | b'#' | b':' | b'[' | b']' | b'@') => ch, + _ => PLAIN, + }; + i += 1; + } + t +} + +const AUTHORITY_MAP: [u8; 256] = build_authority_map(); + /// Shared validation logic for authority bytes. /// Returns the end position of valid authority bytes, or an error. const fn validate_authority_bytes(s: &[u8]) -> Result { @@ -492,7 +512,13 @@ const fn validate_authority_bytes(s: &[u8]) -> Result { // code point. while i < s.len() { let b = s[i]; - let ch = URI_CHARS[b as usize]; + let ch = AUTHORITY_MAP[b as usize]; + + // Most bytes are plain host or userinfo characters. + if ch == PLAIN { + i += 1; + continue; + } if ch == b'/' || ch == b'?' || ch == b'#' { end = i;