0
0
mirror of https://github.com/python/cpython.git synced 2024-11-21 21:09:37 +01:00

gh-126156: Improve performance of creating Morsel objects (#126157)

Replaces the manually constructed loop with a call to `dict.update`
This commit is contained in:
J. Nick Koston 2024-10-31 14:05:40 -05:00 committed by GitHub
parent 0e8665554b
commit dd3c0fa3fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -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):

View File

@ -0,0 +1 @@
Improved performances of creating :py:class:`~http.cookies.Morsel` objects by a factor of 3.8x.