From 4a666d28d7f30f2eb856ffef0ea0343be6cccef1 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 8 Jan 2016 12:37:58 +0100 Subject: AvailableDescriptionLanguages: Use one string for all iterations Do not create strings within the loop, that creates one string per language and does more work than needed. Instead, reserve enough space at the beginning and assign the prefix, and then resize and append inside the loop. Also call exists with the string itself instead of the c_str(), this means that the lookup uses the size information in the string now and does not have to call strlen() on it. --- apt-pkg/deb/deblistparser.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'apt-pkg/deb/deblistparser.cc') diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index bcfbcccc2..baa1e46ec 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -258,12 +258,19 @@ std::vector debListParser::AvailableDescriptionLanguages() { std::vector const understood = APT::Configuration::getLanguages(); std::vector avail; + static constexpr int prefixLen = 12; + static constexpr int avgLanguageLen = 5; + std::string tagname; + + tagname.reserve(prefixLen + avgLanguageLen); + tagname.assign("Description-"); if (Section.Exists("Description") == true) avail.push_back(""); for (std::vector::const_iterator lang = understood.begin(); lang != understood.end(); ++lang) { - std::string const tagname = "Description-" + *lang; - if (Section.Exists(tagname.c_str()) == true) + tagname.resize(prefixLen); + tagname.append(*lang); + if (Section.Exists(tagname) == true) avail.push_back(*lang); } return avail; -- cgit v1.2.3