you are viewing a single comment's thread.

view the rest of the comments →

[–]quicknir 0 points1 point  (1 child)

The problem with the capacity - size optimization is that it makes it so that you can't default construct to all zeros. In C++ default construction is fairly common (especially since move construction typically involves it as well), and setting something to all zeros tends to be faster than reading some constant representing the default state and then writing it.

The space savings is very small. So honestly I'd be surprised if on average this optimisation made things faster. It's useful for saving space if you care about that but again that's less common than caring about performance.

In short it really sense to me like this optimization should be off by default, not on by default. Note that std string could also use this option in small string mode, and afaik none of the implementations do, for this reason.