[issue3982] support .format for bytes

Glyph Lefkowitz report at bugs.python.org
Tue Jan 22 23:51:03 CET 2013


Glyph Lefkowitz added the comment:

On Jan 22, 2013, at 1:46 PM, STINNER Victor <report at bugs.python.org> wrote:

> 2013/1/22 Guido van Rossum <report at bugs.python.org>:
>> Twisted still would like to see this.
> 
> Sorry, but this argument doesn't convince me. A better argument is
> that bytes+bytes+...+bytes is inefficient: it creates a lot of
> temporary objects instead of computing the final size directly, or
> using realloc.

Uh, yes.  That's one of the reasons (given above) that Twisted would still like to see this.  It seemed to me that Guido was stating a fact there, not making an argument.  The Twisted project *would* like to see this, I can assure you, regardless of whether you're convinced or not :).

> str%args and str.format() uses realloc() and overallocates its
> internal buffer to avoid too many calls to realloc().

More importantly, it's fairly easy to add many optimizations of this type to an API in the style of .format(), even if it's not present in the first round; optimizing bytes + bytes + bytes requires slightly scary interactions with refcounting and potentially GC, like the += optimization.  The API just has more information to go on, and that's a good thing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3982>
_______________________________________


More information about the Python-bugs-list mailing list