feat(headers): set will not reallocate whole list if not needed

This commit is contained in:
Simon Cruanes 2025-04-15 10:40:37 -04:00
parent cdac33689a
commit d7a5cca1d4
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -35,7 +35,15 @@ let get ?(f = fun x -> x) x h =
try Some (get_exn ~f x h) with Not_found -> None try Some (get_exn ~f x h) with Not_found -> None
let remove x h = List.filter (fun (k, _) -> not (equal_name_ k x)) h let remove x h = List.filter (fun (k, _) -> not (equal_name_ k x)) h
let set x y h = (x, y) :: List.filter (fun (k, _) -> not (equal_name_ k x)) h
let set x y h =
let h =
if contains x h then
remove x h
else
h
in
(x, y) :: h
let pp out l = let pp out l =
let pp_pair out (k, v) = Format.fprintf out "@[<h>%s: %s@]" k v in let pp_pair out (k, v) = Format.fprintf out "@[<h>%s: %s@]" k v in