I have C++ code that investigates a BIG string and matches lots of substrings. As much as possible, I avoid constructing std::strings, by encoding substrings like this:
char* buffer, size_t bufferSize
Run Code Online (Sandbox Code Playgroud)
At some point, however, I'd like to look up a substring in one of these:
std::unordered_map<std::string, Info> stringToInfo = {...
Run Code Online (Sandbox Code Playgroud)
So, to do that, I go:
stringToInfo.find(std::string(buffer, bufferSize))
Run Code Online (Sandbox Code Playgroud)
That constructs a std::string for the sole purpose of the lookup.
I feel like there's an optimization I could do here, …