diff options
author | Julian Andres Klode <jak@debian.org> | 2016-09-28 00:05:31 +0200 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2016-11-22 22:58:19 +0100 |
commit | c0723bf1a60daf45096998d4ae9feee3c44343f8 (patch) | |
tree | 5dfdfba820dbe501d1a6bf2fafbcba125facd027 /apt-pkg | |
parent | f378b41f9ab2493bcbc5892d482b18826b0b84c0 (diff) |
debListParser: Micro-optimize AvailableDescriptionLanguages()
Generating a string for each version we see is somewhat inefficient.
The problem here is that the Description tag names are longer than
15 byte, and thus require an allocation on the heap, which we should
avoid.
It seems reasonable that 20 characters works for all languages codes
used for archive descriptions, but if not, there's a warning, so
we'll catch that.
This should improve performance by about 2%.
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 15251bce4..ea4d8e063 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -254,18 +254,17 @@ 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-"); + char buf[32] = "Description-"; if (Section.Exists("Description") == true) avail.push_back(""); for (std::vector<std::string>::const_iterator lang = understood.begin(); lang != understood.end(); ++lang) { - tagname.resize(prefixLen); - tagname.append(*lang); - if (Section.Exists(tagname) == true) + if (unlikely(lang->size() > sizeof(buf) - prefixLen)) { + _error->Warning("Ignoring translated description %s", lang->c_str()); + continue; + } + memcpy(buf + prefixLen, lang->c_str(), lang->size()); + if (Section.Exists(StringView(buf, prefixLen + lang->size())) == true) avail.push_back(*lang); } return avail; |