summaryrefslogtreecommitdiff
path: root/apt-pkg/deb/deblistparser.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-09-27 18:28:55 +0200
committerJulian Andres Klode <jak@debian.org>2016-11-22 22:58:18 +0100
commitf903069c139df58d1ba855f7cf02c4a2d4e51dc3 (patch)
treeafeaaa1079fd67e99d7ab37f68eecb37988d5161 /apt-pkg/deb/deblistparser.cc
parent7a3b00b10b6a5a740e07fc1b68a4f3fb3bcdac23 (diff)
Optimize VersionHash() to not need temporary copy of input
Stop copying stuff, and just parse the bytes one by-one to the newly created AddCRC16Byte. This improves the instruction count for an update run from 720,850,121 to 455,801,749 according to callgrind.
Diffstat (limited to 'apt-pkg/deb/deblistparser.cc')
-rw-r--r--apt-pkg/deb/deblistparser.cc20
1 files changed, 6 insertions, 14 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 549e75952..15251bce4 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -353,7 +353,6 @@ unsigned short debListParser::VersionHash()
pkgTagSection::Key::Breaks,
pkgTagSection::Key::Replaces};
unsigned long Result = INIT_FCS;
- char S[1024];
for (auto I : Sections)
{
const char *Start;
@@ -363,23 +362,16 @@ unsigned short debListParser::VersionHash()
/* Strip out any spaces from the text, this undoes dpkgs reformatting
of certain fields. dpkg also has the rather interesting notion of
- reformatting depends operators < -> <= */
- char *J = S;
- for (; Start != End && (J - S) < sizeof(S); ++Start)
+ reformatting depends operators < -> <=, so we drop all = from the
+ string to make that not matter. */
+ for (; Start != End; ++Start)
{
- if (isspace_ascii(*Start) != 0)
+ if (isspace_ascii(*Start) != 0 || *Start == '=')
continue;
- *J++ = tolower_ascii_unsafe(*Start);
-
- /* Normalize <= to < and >= to >. This is the wrong way around, but
- * more efficient that the right way. And since we're only hashing
- * it does not matter which way we normalize. */
- if ((*Start == '<' || *Start == '>') && Start[1] == '=') {
- Start++;
- }
+ Result = AddCRC16Byte(Result, tolower_ascii_unsafe(*Start));
}
- Result = AddCRC16(Result,S,J - S);
+
}
return Result;