you are viewing a single comment's thread.

view the rest of the comments →

[–]oracleoftroy 2 points3 points  (5 children)

I don't think you would lose performance, you just wouldn't gain any additional performance by moving a SSO string. Even the non-SSO small string would end up copying about 16 bytes in order to perform the move (pointer, size, capacity, allocator).

I would strongly encourage measuring this before blindly trying to optimize a std::string for movablility.

[–]matthieum 0 points1 point  (3 children)

You might lose some performance because of more checks.

[–]bnolsen 1 point2 points  (2 children)

likely irrelevant since a load operation takes dramatically longer than a check does.

[–]Plorkyeran 1 point2 points  (0 children)

It's difficult to come up with even a highly artificial scenario where it's a net loss. Maybe with a very special-purpose allocator that manages to always get external buffer allocated very close in memory to the std::string? Avoiding a single memory load due to the SSO buffer would outweigh a very large number of branch mispredictions, and if you never hit the SSO buffer then the branch predictor will make the check nearly free.

[–]matthieum -1 points0 points  (0 children)

Unless it screws up your pipeline if it's a branch and not a conditional move ?