小编2-c*_*lex的帖子

C++ unordered_map<string, ...> lookup without constructing string

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, …

c++ string unordered-map c++11

5
推荐指数
1
解决办法
971
查看次数

标签 统计

c++ ×1

c++11 ×1

string ×1

unordered-map ×1