Skip to content

Commit

Permalink
pythongh-126156: Improve performance of creating Morsel objects
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 committed Oct 30, 2024
1 parent 6f4d64b commit 2d307cb
Showing 1 changed file with 3 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 = {key: "" for key in _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

0 comments on commit 2d307cb

Please sign in to comment.