> Here is the use case I am thinking about:
>
> sbuf.reserveSpace(ioSize);
> bytesRead = read(sbuf.rawSpace(), ioSize);
> sbuf.forceSize(sbuf.size() + bytesRead);
This explains it all, we're thinking about two different use cases.
The other use case is:
sbuf.reserveCapacity(newCapacity);
sbuf.append(something).append(somethingelse).append(verylongstring).append(whoknows).
This could be used e.g. to instantiate error pages from their
templates (pseudo-code):
Sbuf template(.....);
Sbuf errorpage;
errorpage.reserveCapacity(template * reasonable_scaling_factor);
SBufTokenizer t(template);
while (SBuf parsed=t.nextToken("%")) {
errorpage.append(parsed).append(handleCode(t.peek());
}
errorpage.append(t.whatever_remains());
In cases such as this it may not be needed to cow(), so why do it?
> The above case is already handled by rawSpace(), but now I am confused
> why rawSpace() is implemented using unconditional cow() while
> reserveSpace() appears to be optimizing something. That optimization
> seems to be the key here. Perhaps rawSpace() should be deleted and
> reserveCapacity() adjusted to use the same optimization?
> reserveSpace(n) ought to be reserveCapacity(content size + n)
Apart from this, I see the benefit of Amos' suggestion of having
rawSpace also absorb the function of reserveCapacity.
This also covers you observation that both reserveSpace and rawSpace
are maybe not needed, one can do the job of both.
-- /kinkieReceived on Sat Jul 27 2013 - 12:00:51 MDT
This archive was generated by hypermail 2.2.0 : Sat Jul 27 2013 - 12:00:50 MDT