Commit 198ea60
committed
perf(delivery): Cow<str> values in query HashMap, drop into_owned()
form_urlencoded::parse returns Cow<str> pairs where keys and values
that require no percent-decoding are Cow::Borrowed slices into the
query string. Previously parse_query called into_owned() on every
pair unconditionally, converting Borrowed slices to freshly-allocated
Strings even when no decoding was needed.
The HashMap type changes to HashMap<Cow<str>, Cow<str>>:
- Clean alphanumeric keys/values (the common case for template
params like 'port', 'name', 'env') stay Cow::Borrowed → zero
String allocations per query parameter in parse_query.
- Percent-encoded values produce Cow::Owned as before.
- HashMap remains the storage type: O(1) SipHash lookup is
preserved, and the DoS amplification vector (O(P × Q) linear
scan) is still absent.
Cow<str> implements Borrow<str>, so HashMap::get(&str) still
works without any change at the call site in renderer::render.
The renderer's replacement closure calls .as_ref().to_owned() to
produce the required String — same allocation as before, but only
for values that actually match a placeholder.1 parent a187270 commit 198ea60
2 files changed
Lines changed: 20 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
269 | 274 | | |
270 | 275 | | |
271 | 276 | | |
272 | | - | |
273 | | - | |
274 | | - | |
| 277 | + | |
275 | 278 | | |
276 | 279 | | |
277 | 280 | | |
| |||
323 | 326 | | |
324 | 327 | | |
325 | 328 | | |
326 | | - | |
327 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
328 | 335 | | |
329 | 336 | | |
330 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | | - | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | | - | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
0 commit comments