Vindicta-Team / FileXT

Arma 3 addon to store data in files
9 stars 4 forks source link

Use a hashmap instead of comparing strings with strcmp #2

Open Chronophylos opened 4 years ago

Chronophylos commented 4 years ago

Using a hashmap like

std::unordered_map<std::string, std::function<int(char** argv, int argc, std::string fileName)> fn>

is a lot more performant than comparing strings with strcmp in a giant if-else-block.

Or a more simple solution

enum Functions { Open, Close, Write \* ... *\ };
std::unordered_map<std::string, Function> function_map;
Sparker95 commented 4 years ago

Thanks, I think it will do for our simple case, until we have hundreds of functions perhaps.