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 Feb 9, 2019
1 parent 4a3cef7 commit a1944e2
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 @@ -168,7 +168,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 @@ -574,7 +577,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 a1944e2

Please sign in to comment.