My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use physical/string equality in hot URL comparison paths

Two small fixes to avoid generic compare_val in html-generate hot paths:

1. Url.is_prefix: try physical equality (==) before structural (=).
URLs for the same path are shared within a page, so == catches
the common case without walking the parent chain.

2. Link.drop_shared_prefix: l1 and l2 are string lists; use
String.equal instead of (=) to avoid generic comparison dispatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+7 -2
+3 -1
odoc/src/document/url.ml
··· 275 275 | { kind = `LeafPage; parent = None; name = "index" } -> true 276 276 | { kind = `LeafPage; parent = Some p; name = "index" } -> is_prefix p url2 277 277 | _ -> ( 278 - if url1 = url2 then true 278 + (* Physical equality first — same URL is shared within a page, so this 279 + catches the common case without walking the parent chain. *) 280 + if url1 == url2 || url1 = url2 then true 279 281 else 280 282 match url2 with 281 283 | { parent = Some parent; _ } -> is_prefix url1 parent
+4 -1
odoc/src/html/link.ml
··· 70 70 71 71 let rec drop_shared_prefix l1 l2 = 72 72 match (l1, l2) with 73 - | l1 :: l1s, l2 :: l2s when l1 = l2 -> drop_shared_prefix l1s l2s 73 + (* l1 and l2 are string lists. String.equal uses a direct byte compare 74 + without dispatching through compare_val. *) 75 + | l1 :: l1s, l2 :: l2s when String.equal l1 l2 -> 76 + drop_shared_prefix l1s l2s 74 77 | _, _ -> (l1, l2) 75 78 76 79 let href ~config ~resolve t =