For quite a while now, std::string has had Small Buffer Optimization baked in all major implementations.
that allows quite a lot of common operations done with small strings, which are the vast majority of non-empty strings, to be done without heap allocations.
For example:
//Creation won't allocate:
auto text = std::string ("hello");
//Long text might allocate
auto otherText = getReallyLongText();
//But assigning it again won't
otherText = "Shorter text";
With juce::String
, all these operations would allocate, which sometimes becomes costly when you store said Strings in a container and have to copy them around.
It would be great if juce::String
could be implemented with std::string
as the storage mechanism, which I believe could greatly improve performance with String-heavy code.