mirror of https://github.com/python/cpython
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:
parent
0e8665554b
commit
dd3c0fa3fd
|
@ -266,6 +266,8 @@ class Morsel(dict):
|
||||||
"samesite" : "SameSite",
|
"samesite" : "SameSite",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_reserved_defaults = dict.fromkeys(_reserved, "")
|
||||||
|
|
||||||
_flags = {'secure', 'httponly'}
|
_flags = {'secure', 'httponly'}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -273,8 +275,7 @@ class Morsel(dict):
|
||||||
self._key = self._value = self._coded_value = None
|
self._key = self._value = self._coded_value = None
|
||||||
|
|
||||||
# Set default attributes
|
# Set default attributes
|
||||||
for key in self._reserved:
|
dict.update(self, self._reserved_defaults)
|
||||||
dict.__setitem__(self, key, "")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def key(self):
|
def key(self):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Improved performances of creating :py:class:`~http.cookies.Morsel` objects by a factor of 3.8x.
|
Loading…
Reference in New Issue