From: Julian Andres Klode Date: Fri, 8 Jan 2016 11:37:58 +0000 (+0100) Subject: AvailableDescriptionLanguages: Use one string for all iterations X-Git-Tag: 1.2_exp1~19 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/4a666d28d7f30f2eb856ffef0ea0343be6cccef1?ds=inline 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. --- 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;