From 2f8f58512dbb478f23149b57d33f788c26c04445 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 27 Jan 2017 12:30:13 +0100 Subject: avoid malloc if option whitelist is disabled (default) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Config options are checked in various paths, so making "useless" memory allocations wastes time and can also cause problems like #852757. The unneeded malloc was added in ae73a2944a89e0d2406a2aab4a4c082e1e9da3f9. (We have no explicit malloc here – its std:string doing this internally) --- apt-pkg/contrib/configuration.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 8005ef7d4..78a98d614 100644 --- a/apt-pkg/contrib/configuration.cc +++ b/apt-pkg/contrib/configuration.cc @@ -92,10 +92,9 @@ static ConfigType getConfigType(std::string const &type) /*{{{*/ return ConfigType::UNDEFINED; } /*}}}*/ -static void checkFindConfigOptionType(std::string name, ConfigType const type)/*{{{*/ +// checkFindConfigOptionType - workhorse of option checking /*{{{*/ +static void checkFindConfigOptionTypeInternal(std::string name, ConfigType const type) { - if (apt_known_config.empty()) - return; std::transform(name.begin(), name.end(), name.begin(), ::tolower); auto known = apt_known_config.find(name); if (known == apt_known_config.cend()) @@ -151,6 +150,12 @@ static void checkFindConfigOptionType(std::string name, ConfigType const type)/* _error->Warning("Using config option »%s« of type %s as a type %s", name.c_str(), getConfigTypeString(known->second).c_str(), getConfigTypeString(type).c_str()); } +} +static void checkFindConfigOptionType(char const * const name, ConfigType const type) +{ + if (apt_known_config.empty()) + return; + checkFindConfigOptionTypeInternal(name, type); } /*}}}*/ static bool LoadConfigurationIndex(std::string const &filename) /*{{{*/ -- cgit v1.2.3