-----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 [EMAIL PROTECTED] 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----- _______________________________________________ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com