Skip to content

Commit 09f27cc

Browse files
p-r-a-v-i-njacobtylerwalls
authored andcommitted
Refs #35440 -- Optimized parse_header_parameters() for the simplest case.
Added a fast-path to parse_header_parameters Benchmark results (50,000 iterations): - Simple headers: ~73% improvement Thanks Nick Pope (@ngnpope) for the review.
1 parent 2802564 commit 09f27cc

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

django/utils/http.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def parse_header_parameters(line, max_length=MAX_HEADER_LENGTH):
342342
if max_length is not None and len(line) > max_length:
343343
raise ValueError("Unable to parse header parameters (value too long).")
344344

345+
# Fast path for no params.
346+
if ";" not in line:
347+
return line.strip().lower(), {}
348+
345349
parts = _parseparam(";" + line)
346350
key = parts.__next__().lower()
347351
pdict = {}

0 commit comments

Comments
 (0)