From 48cc33f92a23d31e5f8ce6a19a1e9bd7e756a33e Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:36:40 +0000 Subject: [PATCH 1/2] Remove dead code from bun_url Remove unreferenced items from src/url/lib.rs that were carried over from the Zig port but have no callers anywhere in the workspace: - URL::is_localhost() - QueryStringMap::get_index() - QueryStringMap::get() - QueryStringMap::has() - QueryStringMap::get_all() - QueryStringMap::get_all_with_hash_from_offset() - NAME_COUNT_BUF thread_local (already annotated as unused) - commented-out Zig body in get_name_count() - core::cell::RefCell import (only used by NAME_COUNT_BUF) The only consumer of QueryStringMap is src/runtime/api/filesystem_router.rs, which uses init/init_with_scanner/iter/get_name_count/str only. Verified: rg across src/ and build/debug/codegen/, bun bd, bun run rust:check-all (all 10 targets), filesystem_router.test.ts (29 pass). --- src/url/lib.rs | 59 -------------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/src/url/lib.rs b/src/url/lib.rs index 1a1e93f89a92..5670e504a27e 100644 --- a/src/url/lib.rs +++ b/src/url/lib.rs @@ -3,8 +3,6 @@ pub mod error; pub use error::{Error, Result}; -use core::cell::RefCell; - use bun_collections::bit_set::{ArrayBitSet, num_masks_for}; use bun_core::{self, fmt as bun_fmt}; use bun_core::{String as BunString, Tag as BunStringTag, strings}; @@ -375,10 +373,6 @@ impl<'a> URL<'a> { Self::from_string(&BunString::borrow_utf8(input)) } - pub fn is_localhost(&self) -> bool { - self.hostname.is_empty() || self.hostname == b"localhost" || self.hostname == b"0.0.0.0" - } - #[inline] pub fn is_unix(&self) -> bool { self.protocol.starts_with(b"unix") @@ -936,23 +930,9 @@ impl Clone for QueryStringMap { } } -thread_local! { - // Unused in current code (commented-out path in get_name_count). - static NAME_COUNT_BUF: RefCell<[*const [u8]; 8]> = const { RefCell::new([std::ptr::from_ref::<[u8]>(&[]); 8]) }; -} - impl QueryStringMap { pub fn get_name_count(&mut self) -> usize { self.list.len() - // if (this.name_count == null) { - // var count: usize = 0; - // var iterate = this.iter(); - // while (iterate.next(&_name_count) != null) { - // count += 1; - // } - // this.name_count = count; - // } - // return this.name_count.?; } pub fn iter(&self) -> Iterator<'_> { @@ -966,45 +946,6 @@ impl QueryStringMap { &slice[ptr.offset as usize..ptr.offset as usize + ptr.length as usize] } - pub fn get_index(&self, input: &[u8]) -> Option { - let hash = wyhash(input); - self.list.iter().position(|p| p.name_hash == hash) - } - - pub fn get(&self, input: &[u8]) -> Option<&[u8]> { - let hash = wyhash(input); - let i = self.list.iter().position(|p| p.name_hash == hash)?; - Some(self.str(self.list[i].value)) - } - - pub fn has(&self, input: &[u8]) -> bool { - self.get_index(input).is_some() - } - - pub fn get_all<'s>(&'s self, input: &[u8], target: &mut [&'s [u8]]) -> usize { - let hash = wyhash(input); - self.get_all_with_hash_from_offset(target, hash, 0) - } - - pub fn get_all_with_hash_from_offset<'s>( - &'s self, - target: &mut [&'s [u8]], - hash: u64, - offset: usize, - ) -> usize { - let mut remainder = &self.list[offset..]; - let mut target_i: usize = 0; - while !remainder.is_empty() && target_i < target.len() { - let Some(i) = remainder.iter().position(|p| p.name_hash == hash) else { - break; - }; - target[target_i] = self.str(remainder[i].value); - remainder = &remainder[i + 1..]; - target_i += 1; - } - target_i - } - pub fn init_with_scanner( mut scanner: CombinedScanner<'_>, ) -> Result, bun_alloc::AllocError> { From 9ccba66027a054dbe08261d8f46edc9026a6f4d2 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:52:58 +0000 Subject: [PATCH 2/2] Also remove QueryStringMap.name_count field and relax get_name_count to &self The name_count field was part of the same never-enabled caching mechanism as NAME_COUNT_BUF and the commented-out get_name_count body: set to None at all three construction sites, cloned, and never read. With the caching write gone, get_name_count no longer mutates and can take &self. --- src/url/lib.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/url/lib.rs b/src/url/lib.rs index 5670e504a27e..9d860bde4b6d 100644 --- a/src/url/lib.rs +++ b/src/url/lib.rs @@ -900,7 +900,6 @@ pub struct QueryStringMap { slice: *const [u8], pub buffer: Vec, pub list: ParamList, - pub name_count: Option, } impl Clone for QueryStringMap { @@ -925,13 +924,12 @@ impl Clone for QueryStringMap { slice, buffer, list: self.list.clone(), - name_count: self.name_count, } } } impl QueryStringMap { - pub fn get_name_count(&mut self) -> usize { + pub fn get_name_count(&self) -> usize { self.list.len() } @@ -1084,7 +1082,6 @@ impl QueryStringMap { list, buffer: buf, slice: slice_ptr, - name_count: None, })) } @@ -1138,7 +1135,6 @@ impl QueryStringMap { buffer: Vec::new(), // `slice` borrows the caller's query_string; lifetime not tracked here slice: std::ptr::from_ref::<[u8]>(query_string), - name_count: None, })); } @@ -1203,7 +1199,6 @@ impl QueryStringMap { list, buffer: buf, slice: slice_ptr, - name_count: None, })) } }