Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2019-12-04 22:24:49


Krystian Stasiowski wrote:
> On Wed, Dec 4, 2019 at 1:24 PM Peter Dimov via Boost
> <boost_at_[hidden]> wrote:
>
> > Yes, probably. As I said, it's not clear that we should bother with it
> > (I wouldn't), but it at least gives consistent space savings for all
> > short strings.
> >
> > That said, one could use it for N < 32, when the size will be in the
> > same cache line.
>
> What should I do? I can implement this, but since `size()` would be have
> to be called as opposed to simply accessing the member (this already
> happens, since a proxy function is used due to the specialization for zero
> size, but it only returns the member each time so it is easily inlined),
> as Andrey mentioned this may not be cache friendly.

Well as I said, if it were up to me, I wouldn't use this optimization.

    smallest_width_t size_;
    char data_[ N+1 ];

is good enough for me, in all cases, including N == 0. This makes
fixed_string<0> two bytes instead of one, but I'm pretty sure I (and 99.4%
of the Earth population) can live with that.

With Boost components, especially fundamental ones, I always prefer clarity
of implementation over optimizations (at the margin).


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk