|
Re: [z3-five] Re: Patch for testbrowser.py: msg#00097web.zope.z3base.five
-----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@xxxxxxxxxxxxx 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----- |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Intids missing adapter declarations?: 00097, Philipp von Weitershausen |
|---|---|
| Next by Date: | [ANN] CPSSkins4Five and CPS4/Z3ECM Paris sprint report: 00097, Jean-Marc Orliaguet |
| Previous by Thread: | Re: [z3-five] Re: Patch for testbrowser.pyi: 00097, Paul Winkler |
| Next by Thread: | Re: Re: Patch for testbrowser.py: 00097, Benji York |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |