[Zope3-dev] Re: [z3-five] Re: Patch for testbrowser.py
Tres Seaver
tseaver at palladion.com
Fri Apr 21 17:45:29 EDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Paul Winkler wrote:
> 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:
I think this may be a fossil from a much earlier version of Python, in
which 'list.extend' had undesirable performance (the new one is
O(1)-amortized, I think).
Tres.
- --
===================================================================
Tres Seaver +1 202-558-7113 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFESVJ5+gerLs4ltQ4RAlseAKDVL5ABbRYGSzNtaLUVeu37WPTBCwCfW9pp
c1gst1YN+xssxW2ZFhHWt88=
=bcvP
-----END PGP SIGNATURE-----
More information about the Zope3-dev
mailing list