[squid-dev] [PATCH] Extend SBufContainerJoin to have prefix and suffix arguments

Alex Rousskov rousskov at measurement-factory.com
Thu Nov 3 22:55:46 UTC 2016


On 11/03/2016 03:19 PM, Kinkie wrote:
> On Tue, Nov 1, 2016 at 8:47 PM, Alex Rousskov wrote:
>> On 11/01/2016 02:02 PM, Kinkie wrote:
>>>   the attached patch extends SBufContainerJoin to have prefix and
>>> suffix arguments. 

>> I recommend reworking this by adding a dest parameter:
>> SBuf &ContainerToSBuf(SBuf &dest, ...);


> Can simply return the modified SBuf.

>  SBuf
> -SBufContainerJoin(const Container &items, const SBuf& separator)
> +JoinContainerIntoSBuf(SBuf dest, const ContainerIterator &begin,

This implementation does not avoid copies in a general case: When I
already have an SBuf with some content, I have to feed my writeable SBuf
to ContainerToSBuf() to avoid allocating and copying.

AFAICT, the reasonable implementation options are:

  1. Your old simpler implementation without "dest".
  2. A more efficient implementation with writeable "dest".

The latest implementation has the complexity of #2 but lacks its
efficiency. I do not think it is a good API.

Alex.



More information about the squid-dev mailing list