[Python-Dev] Re: New public PyUnicodeBuilder C API

2022年5月16日 05:41:13 -0700

On 2022年5月16日 14:22:44 +0200
Victor Stinner <[email protected]> wrote:
> On Mon, May 16, 2022 at 2:11 PM Antoine Pitrou <[email protected]> wrote:
> > > PyUnicodeBuilder_Init(&builder);
> > >
> > > // Overallocation is more efficient if the final length is 
> > > unknown
> > > PyUnicodeBuilder_EnableOverallocation(&builder);
> > > PyUnicodeBuilder_WriteStr(&builder, key);
> > > PyUnicodeBuilder_WriteChar(&builder, '=');
> > >
> > > // Disable overallocation before the last write
> > > PyUnicodeBuilder_DisableOverallocation(&builder); 
> >
> > Having to manually enable or disable overallocation doesn't sound right.
> > Overallocation should be done *before* writing, not after. If there are
> > N bytes remaining and you write N bytes, then no reallocation should
> > occur. 
> 
> Calling these functions has no immediate effect on the current buffer.
> EnableOverallocation() doesn't enlarge the buffer. Even if the buffer
> is currently "over allocated", DisableOverallocation() leaves the
> buffer unchanged. Only the next writes will use a different strategy
> depending on the current setting. Only the Finish() function shrinks
> the buffer.
Hmm, it appears I had misread the example. Sorry for the noise.
Regards
Antoine.
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/DJU5TQN5CPKYITWU7R5AJOT7MF7A5V3X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to