Closed 3Hren closed 4 months ago
We have a bit of strange code in https://github.com/yanet-platform/yanet/blob/d53654af2450a6ed7630a4f6e6a2ac16abe50d17/dataplane/dataplane.cpp#L1772 Here, we parse config file and fill the https://github.com/yanet-platform/yanet/blob/d53654af2450a6ed7630a4f6e6a2ac16abe50d17/dataplane/dataplane.h#L331 using the following pattern:
if (exist(json, "some_key")) { configValues[eConfigType::some_enum] = json["some_key"]; }
, but such pattern is prone to copy-paste errors. What if we slightly change the key and check for existing for another one?
I suggest to:
configValues[eConfigType::some_enum] = json.value("some_key", 0); // Or meaningful default value.
map<enum, uint64>
We can start with dataplane config, but, of course, this can be propagated further to other configs.
Slightly faster access, as there is no need to recheck while accessing values. More precisely, this function will be removed:
uint64_t cDataPlane::getConfigValue(const eConfigType& type) const { if (configValues.find(type) == configValues.end()) { YADECAP_LOG_ERROR("unknown variable\n"); return 0; } return configValues.find(type)->second; }
The problem
We have a bit of strange code in https://github.com/yanet-platform/yanet/blob/d53654af2450a6ed7630a4f6e6a2ac16abe50d17/dataplane/dataplane.cpp#L1772 Here, we parse config file and fill the https://github.com/yanet-platform/yanet/blob/d53654af2450a6ed7630a4f6e6a2ac16abe50d17/dataplane/dataplane.h#L331 using the following pattern:
, but such pattern is prone to copy-paste errors. What if we slightly change the key and check for existing for another one?
I suggest to:
map<enum, uint64>
to a named struct.We can start with dataplane config, but, of course, this can be propagated further to other configs.
The profit
Slightly faster access, as there is no need to recheck while accessing values. More precisely, this function will be removed:
Alternatives