On Mon, 16 May 2022 14:22:44 +0200
Victor Stinner <vstin...@python.org> wrote:
> On Mon, May 16, 2022 at 2:11 PM Antoine Pitrou <anto...@python.org> 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 -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DJU5TQN5CPKYITWU7R5AJOT7MF7A5V3X/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to