Skip to content

Commit

Permalink
gh-126156: Improve performance of creating Morsel objects (#126157)
Browse files Browse the repository at this point in the history
Replaces the manually constructed loop with a call to `dict.update`
  • Loading branch information
bdraco authored Oct 31, 2024
1 parent 0e86655 commit dd3c0fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ class Morsel(dict):
"samesite" : "SameSite",
}

_reserved_defaults = dict.fromkeys(_reserved, "")

_flags = {'secure', 'httponly'}

def __init__(self):
# Set defaults
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved performances of creating :py:class:`~http.cookies.Morsel` objects by a factor of 3.8x.

0 comments on commit dd3c0fa

Please sign in to comment.