config_parser: Reduce number of file reads
This changes focuses on reducing the number of Parser() constructions to
limit the number of duplicate file reads.
Change-Id: I05df943844c70dc6aa729ab744d2d405cbfe2c76
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index ec9e6d9..4308f96 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -79,17 +79,11 @@
bool Configuration::getDHCPPropFromConf(const std::string& prop)
{
- fs::path confPath = manager.getConfDir();
auto interfaceStrList = getInterfaces();
- // get the first interface name, we need it to know config file name.
- auto interface = *interfaceStrList.begin();
- auto fileName = systemd::config::networkFilePrefix + interface +
- systemd::config::networkFileSuffix;
-
- confPath /= fileName;
// systemd default behaviour is all DHCP fields should be enabled by
// default.
- config::Parser parser(confPath);
+ config::Parser parser(config::pathForIntfConf(manager.getConfDir(),
+ *interfaceStrList.begin()));
const auto& values = parser.getValues("DHCP", prop);
if (values.empty())