[Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?] (original) (raw)
Guido van Rossum guido at python.org
Wed Feb 15 02:15:03 CET 2006
- Previous message: [Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?]
- Next message: [Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/14/06, Jim Jewett <jimjjewett at gmail.com> wrote:
On 2/14/06, Neil Schemenauer wrote: > People could spell it bytes(s.encode('latin-1')) in order to make it > work in 2.X.
Guido wrote: > At the cost of an extra copying step. That sounds like an implementation issue. If it is important enough to matter, then why not just add some smarts to the bytes constructor?
Short answer: you can't.
If the argument is a str, and the constructor owns the only reference, then go ahead and use the argument's own underlying array; the string itself will be deallocated when (or before) the constructor returns, so no one else can use it expecting an immutable.
Hard to explain, but the VM usually keeps an extra reference on the stack so the refcount is never 1. But you can't rely on that so assuming that it's safe to reuse the storage if it's >1. Also, since the str's underlying array is allocated inline with the str header, this require str and bytes to have the same object layout. But since bytes are mutable, they can't.
Summary: you don't understand the implementation well enough to suggest these kinds of things.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?]
- Next message: [Python-Dev] PEP 332 revival in coordination with pep 349? [ Was:Re: release plan for 2.5 ?]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]