|
Re: [z3-five] Re: Patch for testbrowser.py: msg#00094web.zope.z3base.five
On Fri, Apr 21, 2006 at 04:07:43PM +0200, Daniel Nouri wrote: > The relevant code in Zope2's ZPublisher.HTTPResponse.__str__: > > # ... we just built a headersl list using self.heders > if self.cookies: > headersl = headersl+self._cookie_list() > headersl[len(headersl):] = [self.accumulated_headers, body] > return '\n'.join(headersl) > > Maybe this can shed some light on whether we want to include that patch. As an aside: What's with assigning to headersl[len(headersl):] instead of calling headersl.extend(...)? I've seen this idiom a couple of times and I always wonder why, it's much less readable IMO. I doubt it's supposed to be an optimization, since this code runs only once per request; anyway, the two idioms are about equivalent in speed AFAICT. If it were in a performance-sensitive loop, a bit faster and still quite readable would be: headersl += [self.accumulated_headers, body] timeit confirms this, here on python 2.4.2: >>> import timeit >>> slicer = timeit.Timer('x[len(x):] = [4,5,6]', 'x=[1,2,3]') >>> adder = timeit.Timer('x += [4,5,6]', 'x=[1,2,3]') >>> extender = timeit.Timer('x.extend([4,5,6])', 'x=[1,2,3]') >>> n = 1000000) >>> slicer.timeit(n) 2.6605889797210693 >>> extender.timeit(n) 2.5256669521331787 >>> adder.timeit(n) 1.9388060569763184 -- Paul Winkler http://www.slinkp.com |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Re: Patch for testbrowser.py: 00094, Benji York |
|---|---|
| Next by Date: | Intids missing adapter declarations?: 00094, Jean-Marc Orliaguet |
| Previous by Thread: | Re: Patch for testbrowser.pyi: 00094, Daniel Nouri |
| Next by Thread: | Re: [z3-five] Re: Patch for testbrowser.py: 00094, Tres Seaver |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |