Re: [RFC] Time to talk about StringNG merge again?

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Sat, 27 Jul 2013 14:32:50 -0600

On 07/27/2013 01:03 PM, Kinkie wrote:
> On Sat, Jul 27, 2013 at 8:31 PM, Alex Rousskov wrote:
>> On 07/27/2013 12:00 PM, Kinkie wrote:
>>>>> 1a. Reserve total buffer capacity. Ensure exclusive buffer ownership.
>>>>>
>>>>> 1b. Reserve buffer space. Ensure exclusive buffer ownership.
>>>>>
>>>>> 2. Reserve N space bytes for the caller to append to. No guarantees
>>>>> regarding buffer ownership are provided.

>> // 1a.
>> void reserveCapacity(size_type minCap) {
>> cow(minCap);
>> }
>>
>> // 1b.
>> void reserveSpace(size_type minSpace) {
>> // check that the sum below does not exceed size_type
>> Must(size() <= size_type's limit - minSpace);
>> reserveCapacity(size() + minSpace);
>> }
>>
>> // 2.
>> char *rawSpace(size_type minSpace) {
>> ... your optimization goes here ...
>> return pointer to space;
>> }

> I don't understand how this helps with the append() use-case.

append() should call rawSpace(). rawSpace() is optimized.

> The most likely useage pattern would be 2, and that forces a
> potentially unneeded cow()..

rawSpace() does not force that because your optimization should be
placed there.

> IMO the three methods would be:
>
> void reserveCapacity(size_type minCap) {
> if (needed())
> cow();
> }

I assume that cow() already implements the "if needed" part.

> void reserveSpace(size_type minSpace) {
> reserveCapacity(minSpace+length());
> }

Yes, plus the size_type overflow check.

> char *rawSpace(size_type minSpace) {
> cow(minSpace+length());
> return *freespace;
> }

No, this needs your no-cow optimization instead. That optimization is
currently in SBuf::reserveSpace() but should be in rawSpace().

HTH,

Alex.
Received on Sat Jul 27 2013 - 20:33:05 MDT

This archive was generated by hypermail 2.2.0 : Sun Jul 28 2013 - 12:00:06 MDT