diff options
| author | Pravin Kamble <iampbkamble@gmail.com> | 2026-01-13 20:21:50 +0530 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-04-08 17:30:05 -0400 |
| commit | 09f27cc373eb1e6e5e8b286204809a79b61d55c3 (patch) | |
| tree | 481be2392018917ae8f1d404b23026e233ed84be /django | |
| parent | 280256499c5b2d636949f3c8cb52159a8e4c26bb (diff) | |
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.
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/http.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 2950f3e695..f72f54e958 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -342,6 +342,10 @@ def parse_header_parameters(line, max_length=MAX_HEADER_LENGTH): if max_length is not None and len(line) > max_length: raise ValueError("Unable to parse header parameters (value too long).") + # Fast path for no params. + if ";" not in line: + return line.strip().lower(), {} + parts = _parseparam(";" + line) key = parts.__next__().lower() pdict = {} |
