Commit 8af4f1e
perf: cache special-scheme flag and switch scheme checks to map lookups
- Call protocolComponentMatchesSpecialScheme() once per New() and reuse
the result for both the hostname and pathname branches instead of
matching the component regex against the five special schemes twice.
- Replace specialSchemeList with a single map[string]struct{} (renamed
to specialSchemeSet since the value is now a set, not an ordered list)
so the per-component lookups in processHostnameForInit and
processPathnameForInit are O(1). protocolComponentMatchesSpecialScheme
just iterates the map keys, since order is irrelevant when the loop
returns on the first hit.
- Collapse the port-defaulting loop into a direct DefaultPorts lookup
gated on specialSchemeSet membership, so user-added DefaultPorts
entries cannot silently trigger special-scheme behaviour. The
processedInit protocol is lowercased before the check because in
"pattern" mode processProtocolForInit does not canonicalize, and the
protocol component is later compiled with canonicalizeProtocol which
lowercases — so a mixed-case literal like "HTTP" should behave as
"http" for port defaulting.
~5-10%% reduction in ns/op on New() across pattern benchmarks.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 92fee3d commit 8af4f1e
2 files changed
Lines changed: 28 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
21 | 27 | | |
22 | 28 | | |
23 | 29 | | |
| |||
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
103 | | - | |
| 109 | + | |
104 | 110 | | |
105 | 111 | | |
106 | 112 | | |
| |||
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
168 | | - | |
169 | | - | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
170 | 185 | | |
171 | | - | |
172 | 186 | | |
173 | 187 | | |
174 | 188 | | |
| |||
191 | 205 | | |
192 | 206 | | |
193 | 207 | | |
| 208 | + | |
| 209 | + | |
194 | 210 | | |
195 | 211 | | |
196 | 212 | | |
197 | 213 | | |
198 | 214 | | |
199 | 215 | | |
200 | | - | |
| 216 | + | |
201 | 217 | | |
202 | 218 | | |
203 | 219 | | |
| |||
219 | 235 | | |
220 | 236 | | |
221 | 237 | | |
222 | | - | |
| 238 | + | |
223 | 239 | | |
224 | 240 | | |
225 | 241 | | |
| |||
629 | 645 | | |
630 | 646 | | |
631 | 647 | | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
| 648 | + | |
| 649 | + | |
636 | 650 | | |
637 | 651 | | |
638 | 652 | | |
| |||
657 | 671 | | |
658 | 672 | | |
659 | 673 | | |
660 | | - | |
661 | | - | |
662 | | - | |
663 | | - | |
| 674 | + | |
| 675 | + | |
664 | 676 | | |
665 | 677 | | |
666 | 678 | | |
| |||
0 commit comments