diff options
author | Julian Andres Klode <jak@debian.org> | 2016-01-08 12:37:58 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-01-08 12:37:58 +0100 |
commit | 4a666d28d7f30f2eb856ffef0ea0343be6cccef1 (patch) | |
tree | fdea3937359ee4d035db4a8dde76edf4b1a9e697 /apt-pkg/deb | |
parent | 24c7db2edea692c3778c021c053a2316203bfa03 (diff) |
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.
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 11 |
1 files changed, 9 insertions, 2 deletions
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<std::string> debListParser::AvailableDescriptionLanguages() { std::vector<std::string> const understood = APT::Configuration::getLanguages(); std::vector<std::string> 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<std::string>::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; |