[quote=“TheVinn”]Why doesn’t String::length guarantee a constant-time execution? It seems that since you have the pimpl (StringHolder I think), this should be easy.
Also, String::length doesn’t adhere to the definition of std::string::length, which is defined as std::distance (begin(), end()). Specifically, std::string may contain embedded nulls. While a juce::String will consider the null terminator to be the end of the string.
Or did I misunderstand the code?[/quote]
Yes, I’ve often considered thought about trying that, but without building elaborate benchmark tests, it’s impossible to know whether it’d actually improve performance or not in the general case. And it’d take a significant amount of work to rewrite it, so I’d need some pretty good evidence that it’d be worthwhile.
I’ve also considered just using a std::string inside the juce::String as the storage layer, in the assumption that the people who write the std library will have made it as fast as possible. But that’d also just be an experiment that could easily fail - I once tried replacing the juce array in the Path class with a std::vector and performance dropped by an inexplicable 10x.