Skip to content

Commit

Permalink
perf(respone): Lazy instantiation of the extra headers list object
Browse files Browse the repository at this point in the history
  • Loading branch information
kgriffs committed Jan 29, 2019
1 parent 707676e commit 5c35b3c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions falcon/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def __init__(self, options=None):
# NOTE(kgriffs): Collection of additional headers as a list of raw
# tuples, to use in cases where we need more control over setting
# headers and duplicates are allowable or even necessary.
self._extra_headers = []
#
# PERF(kgriffs): Save some CPU cycles and a few bytes of RAM by
# only instantiating the list object later on IFF it is needed.
self._extra_headers = None

self.options = options if options else ResponseOptions()

Expand Down Expand Up @@ -563,7 +566,10 @@ def append_header(self, name, value):
name = name.lower()

if name == 'set-cookie':
self._extra_headers.append((name, value))
if not self._extra_headers:
self._extra_headers = [(name, value)]
else:
self._extra_headers.append((name, value))
else:
if name in self._headers:
value = self._headers[name] + ', ' + value
Expand Down

0 comments on commit 5c35b3c

Please sign in to comment.