When pass const TCHAR* to TMap::Find, implicitly FString temporary object is created.
Then literal string is copied to FString temporary object. this is slow.
I don’t want this. because it’s needless.
I think Hash value can be calculated with const TCAHR*(null-terminated).
However, this will be correct only if you’re intentionally want to hash pointers rather than strings, so different pointers will be considered different even if they contain the same strings.
Just posted a way to compare and store pointers rather than their string content, and realized that I didn’t understand correctly your question. The pointer could not always be stored in the map.
Consider the case with STL’s unordered set that has no such fallback to the “owning” string object:
std::string exclamation()
{
return "!!1";
}
void FillSet(std::unordered_set<const char*>& set)
{
const char hello[] = "hello";
std::string world = "world";
set.insert(hello); // pointer to the local variable
set.insert(world.c_str()); // pointer to the local variable
set.insert(exclamation().c_str()); // pointer to the temporary
}
void Foo()
{
std::unordered_set<const char*> set;
FillSet(set);
// UB: all pointers that are stored in the 'set' are invalid
for (const char* s : set)
ObserveBugs(s);
}
This is quite an error-prone code, perhaps, Epic considered to make their TSet/TMap a bit more highlevel and error-proof.