summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorJ. Nick Koston <nick@koston.org>2024-10-31 19:05:40 (GMT)
committerGitHub <noreply@github.com>2024-10-31 19:05:40 (GMT)
commitdd3c0fa3fd2795326dae0e0ed63c668f5506cf32 (patch)
tree74f97839c0d1159f5dcff80539e68f71c15fb1a5 /Lib/http
parent0e8665554b2f1334e530fd6de5b3a4e908405419 (diff)
downloadcpython-dd3c0fa3fd2795326dae0e0ed63c668f5506cf32.zip
cpython-dd3c0fa3fd2795326dae0e0ed63c668f5506cf32.tar.gz
cpython-dd3c0fa3fd2795326dae0e0ed63c668f5506cf32.tar.bz2
gh-126156: Improve performance of creating `Morsel` objects (#126157)
Replaces the manually constructed loop with a call to `dict.update`
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/cookies.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
index 6b9ed24..d7e8d08 100644
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -266,6 +266,8 @@ class Morsel(dict):
"samesite" : "SameSite",
}
+ _reserved_defaults = dict.fromkeys(_reserved, "")
+
_flags = {'secure', 'httponly'}
def __init__(self):
@@ -273,8 +275,7 @@ class Morsel(dict):
self._key = self._value = self._coded_value = None
# Set default attributes
- for key in self._reserved:
- dict.__setitem__(self, key, "")
+ dict.update(self, self._reserved_defaults)
@property
def key(self):