Skip to content

Commit 8ba982b

Browse files
committed
feat(headers): set will not reallocate whole list if not needed
1 parent c62487e commit 8ba982b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/core/headers.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ let get ?(f = fun x -> x) x h =
3535
try Some (get_exn ~f x h) with Not_found -> None
3636
3737
let remove x h = List.filter (fun (k, _) -> not (equal_name_ k x)) h
38-
let set x y h = (x, y) :: List.filter (fun (k, _) -> not (equal_name_ k x)) h
38+
39+
let set x y h =
40+
let h =
41+
if contains x h then
42+
remove x h
43+
else
44+
h
45+
in
46+
(x, y) :: h
3947
4048
let pp out l =
4149
let pp_pair out (k, v) = Format.fprintf out "@[<h>%s: %s@]" k v in

0 commit comments

Comments
 (0)