summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-01-17 14:34:45 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-02-18 13:39:26 +0100
commit8c10048dce06ee0f160c86a6df07f0e6d2c34242 (patch)
tree7d18b03a24c3ce41c76904cd6ccb8430e7638dc4
parent62683ed6459e874119f3346d8be66b85e8a90533 (diff)
Use a 32-bit djb VersionHash instead of CRC-16
-rw-r--r--apt-pkg/deb/deblistparser.cc8
-rw-r--r--apt-pkg/deb/deblistparser.h4
-rw-r--r--apt-pkg/edsp/edsplistparser.cc2
-rw-r--r--apt-pkg/edsp/edsplistparser.h2
-rw-r--r--apt-pkg/pkgcache.h2
-rw-r--r--apt-pkg/pkgcachegen.cc6
-rw-r--r--apt-pkg/pkgcachegen.h6
7 files changed, 15 insertions, 15 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc
index 7614423df..33c83f8f0 100644
--- a/apt-pkg/deb/deblistparser.cc
+++ b/apt-pkg/deb/deblistparser.cc
@@ -339,7 +339,7 @@ bool debListParser::UsePackage(pkgCache::PkgIterator &Pkg,
// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
// ---------------------------------------------------------------------
/* */
-unsigned short debListParser::VersionHash()
+uint32_t debListParser::VersionHash()
{
static constexpr pkgTagSection::Key Sections[] ={
pkgTagSection::Key::Installed_Size,
@@ -350,7 +350,7 @@ unsigned short debListParser::VersionHash()
pkgTagSection::Key::Conflicts,
pkgTagSection::Key::Breaks,
pkgTagSection::Key::Replaces};
- unsigned long Result = INIT_FCS;
+ unsigned long Result = 5381;
for (auto I : Sections)
{
const char *Start;
@@ -371,7 +371,7 @@ unsigned short debListParser::VersionHash()
}
if (isspace_ascii(*Start) != 0 || *Start == '=')
continue;
- Result = AddCRC16Byte(Result, tolower_ascii_unsafe(*Start));
+ Result = 33 * Result + tolower_ascii_unsafe(*Start);
}
@@ -991,7 +991,7 @@ unsigned char debListParser::GetPrio(string Str)
return Out;
}
/*}}}*/
-bool debListParser::SameVersion(unsigned short const Hash, /*{{{*/
+bool debListParser::SameVersion(uint32_t Hash, /*{{{*/
pkgCache::VerIterator const &Ver)
{
if (pkgCacheListParser::SameVersion(Hash, Ver) == false)
diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h
index a04187c45..eefce2a6a 100644
--- a/apt-pkg/deb/deblistparser.h
+++ b/apt-pkg/deb/deblistparser.h
@@ -64,8 +64,8 @@ class APT_HIDDEN debListParser : public pkgCacheListParser
virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE;
virtual APT::StringView Description_md5() APT_OVERRIDE;
- virtual unsigned short VersionHash() APT_OVERRIDE;
- virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE;
+ virtual uint32_t VersionHash() APT_OVERRIDE;
+ virtual bool SameVersion(uint32_t Hash, pkgCache::VerIterator const &Ver) APT_OVERRIDE;
virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
pkgCache::VerIterator &Ver) APT_OVERRIDE;
virtual map_filesize_t Offset() APT_OVERRIDE {return iOffset;};
diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc
index 96de2b997..45abdbc61 100644
--- a/apt-pkg/edsp/edsplistparser.cc
+++ b/apt-pkg/edsp/edsplistparser.cc
@@ -59,7 +59,7 @@ APT::StringView edspLikeListParser::Description_md5()
}
/*}}}*/
// ListParser::VersionHash - Compute a unique hash for this version /*{{{*/
-unsigned short edspLikeListParser::VersionHash()
+uint32_t edspLikeListParser::VersionHash()
{
if (Section.Exists("APT-Hash") == true)
return Section.FindI("APT-Hash");
diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h
index 2c136026d..41bfd1f79 100644
--- a/apt-pkg/edsp/edsplistparser.h
+++ b/apt-pkg/edsp/edsplistparser.h
@@ -27,7 +27,7 @@ class APT_HIDDEN edspLikeListParser : public debListParser
virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE;
virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE;
virtual APT::StringView Description_md5() APT_OVERRIDE;
- virtual unsigned short VersionHash() APT_OVERRIDE;
+ virtual uint32_t VersionHash() APT_OVERRIDE;
explicit edspLikeListParser(FileFd *File);
virtual ~edspLikeListParser();
diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h
index 8d31e4de9..84fc56db8 100644
--- a/apt-pkg/pkgcache.h
+++ b/apt-pkg/pkgcache.h
@@ -643,7 +643,7 @@ struct pkgCache::Version
No two packages in existence should have the same VerStr
and Hash with different contents. */
- unsigned short Hash;
+ uint32_t Hash;
/** \brief unique sequel ID */
map_id_t ID;
/** \brief parsed priority value */
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index dfac0ae1c..5a7272e84 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -376,7 +376,7 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator
map_pointer_t *LastVer = &Pkg->VersionList;
void const * oldMap = Map.Data();
- unsigned short const Hash = List.VersionHash();
+ auto Hash = List.VersionHash();
if (Ver.end() == false)
{
/* We know the list is sorted so we use that fact in the search.
@@ -849,7 +849,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver,
map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver,
APT::StringView const &VerStr,
map_pointer_t const ParentPkg,
- unsigned short const Hash,
+ uint32_t Hash,
map_pointer_t const Next)
{
// Get a structure
@@ -1234,7 +1234,7 @@ bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, StringVi
return true;
}
/*}}}*/
-bool pkgCacheListParser::SameVersion(unsigned short const Hash, /*{{{*/
+bool pkgCacheListParser::SameVersion(uint32_t Hash, /*{{{*/
pkgCache::VerIterator const &Ver)
{
return Hash == Ver->Hash;
diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h
index 55bf57418..70192c28e 100644
--- a/apt-pkg/pkgcachegen.h
+++ b/apt-pkg/pkgcachegen.h
@@ -109,7 +109,7 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/
bool NewGroup(pkgCache::GrpIterator &Grp, APT::StringView Name);
bool NewPackage(pkgCache::PkgIterator &Pkg, APT::StringView Name, APT::StringView Arch);
map_pointer_t NewVersion(pkgCache::VerIterator &Ver, APT::StringView const &VerStr,
- map_pointer_t const ParentPkg, unsigned short const Hash,
+ map_pointer_t const ParentPkg, uint32_t Hash,
map_pointer_t const Next);
map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang, APT::StringView md5sum,map_stringitem_t const idxmd5str);
bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List);
@@ -201,13 +201,13 @@ class APT_HIDDEN pkgCacheListParser
virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0;
virtual std::vector<std::string> AvailableDescriptionLanguages() = 0;
virtual APT::StringView Description_md5() = 0;
- virtual unsigned short VersionHash() = 0;
+ virtual uint32_t VersionHash() = 0;
/** compare currently parsed version with given version
*
* \param Hash of the currently parsed version
* \param Ver to compare with
*/
- virtual bool SameVersion(unsigned short const Hash, pkgCache::VerIterator const &Ver);
+ virtual bool SameVersion(uint32_t Hash, pkgCache::VerIterator const &Ver);
virtual bool UsePackage(pkgCache::PkgIterator &Pkg,
pkgCache::VerIterator &Ver) = 0;
virtual map_filesize_t Offset() = 0;