]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/deb/deblistparser.cc
Optimize VersionHash() to not need temporary copy of input
[apt.git] / apt-pkg / deb / deblistparser.cc
index 549e75952885ad0af823ed791ecf261a61a2f9e5..15251bce433d2b0d1c4658acf39d8db20ef460be 100644 (file)
@@ -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;