summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgcache.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/pkgcache.cc')
-rw-r--r--apt-pkg/pkgcache.cc101
1 files changed, 35 insertions, 66 deletions
diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc
index 7eb5ab10b..68efcaddc 100644
--- a/apt-pkg/pkgcache.cc
+++ b/apt-pkg/pkgcache.cc
@@ -31,7 +31,6 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/version.h>
-#include <zlib.h>
#include <algorithm>
#include <sstream>
#include <string>
@@ -39,6 +38,7 @@
#include <stddef.h>
#include <string.h>
#include <sys/stat.h>
+#include <xxhash.h>
#include <apti18n.h>
/*}}}*/
@@ -94,7 +94,7 @@ pkgCache::Header::Header()
VerSysName = 0;
Architecture = 0;
SetArchitectures(0);
- SetHashTableSize(_config->FindI("APT::Cache-HashTableSize", 50503));
+ SetHashTableSize(_config->FindI("APT::Cache-HashTableSize", 196613));
memset(Pools,0,sizeof(Pools));
CacheFileSize = 0;
@@ -127,10 +127,7 @@ bool pkgCache::Header::CheckSizes(Header &Against) const
/* */
pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), VS(nullptr), d(NULL)
{
- // call getArchitectures() with cached=false to ensure that the
- // architectures cache is re-evaluated. this is needed in cases
- // when the APT::Architecture field changes between two cache creations
- MultiArchEnabled = APT::Configuration::getArchitectures(false).size() > 1;
+ MultiArchEnabled = true;
if (DoMap == true)
ReMap();
}
@@ -209,83 +206,55 @@ bool pkgCache::ReMap(bool const &Errorchecks)
map_id_t pkgCache::sHash(StringView Str) const
{
uint32_t Hash = 5381;
- for (auto I = Str.begin(); I != Str.end(); ++I)
- Hash = 33 * Hash + tolower_ascii_unsafe(*I);
- return Hash % HeaderP->GetHashTableSize();
-}
-
-#ifdef HAVE_FMV_SSE42_AND_CRC32
-__attribute__((target("sse4.2"))) static uint32_t hash32(uint32_t crc32, const unsigned char *input, size_t size)
-{
- if (input == nullptr)
- return 0;
-
- crc32 ^= 0xffffffffU;
-#ifdef HAVE_FMV_SSE42_AND_CRC32DI
- while (size >= 8) {
- crc32 = __builtin_ia32_crc32di(crc32, *(uint64_t *)input);
- input += 8;
- size -= 8;
- }
-
- if (size >= 4) {
-#else
- while (size >= 4) {
-#endif
- crc32 = __builtin_ia32_crc32si(crc32, *(uint32_t *)input);
- input += 4;
- size -= 4;
- }
-
- if (size >= 2) {
- crc32 = __builtin_ia32_crc32hi(crc32, *(uint16_t *)input);
- input += 2;
- size -= 2;
- }
-
- if (size >= 1) {
- crc32 = __builtin_ia32_crc32qi(crc32, *(uint8_t *)input);
- input += 1;
- size -= 1;
+ auto I = Str.begin();
+ auto End = Str.end();
+ for (; I + 7 < End; I += 8)
+ {
+ Hash = (33u * 33u * 33u * 33u * 33u * 33u * 33u * 33u * Hash +
+ 33u * 33u * 33u * 33u * 33u * 33u * 33u * tolower_ascii_unsafe(I[0]) +
+ 33u * 33u * 33u * 33u * 33u * 33u * tolower_ascii_unsafe(I[1]) +
+ 33u * 33u * 33u * 33u * 33u * tolower_ascii_unsafe(I[2]) +
+ 33u * 33u * 33u * 33u * tolower_ascii_unsafe(I[3]) +
+ 33u * 33u * 33u * tolower_ascii_unsafe(I[4]) +
+ 33u * 33u * tolower_ascii_unsafe(I[5]) +
+ 33u * tolower_ascii_unsafe(I[6]) +
+ tolower_ascii_unsafe(I[7]));
}
- crc32 ^= 0xffffffffU;
- return crc32;
-}
-
-__attribute__((target("default")))
-#endif
-static uint32_t hash32(uint32_t crc32, const unsigned char *input, size_t size)
-{
- return adler32(crc32, input, size);
+ for (; I != End; ++I)
+ Hash = 33u * Hash + tolower_ascii_unsafe(*I);
+ return Hash % HeaderP->GetHashTableSize();
}
-
uint32_t pkgCache::CacheHash()
{
pkgCache::Header header = {};
- uLong adler = hash32(0L, Z_NULL, 0);
+ XXH3_state_t *state = XXH3_createState();
if (Map.Size() < sizeof(header))
- return adler;
+ return 0;
+
+ XXH3_64bits_reset(state);
memcpy(&header, GetMap().Data(), sizeof(header));
header.Dirty = false;
header.CacheFileSize = 0;
- adler = hash32(adler,
- reinterpret_cast<const unsigned char *>(PACKAGE_VERSION),
- APT_ARRAY_SIZE(PACKAGE_VERSION));
+ XXH3_64bits_update(state,
+ reinterpret_cast<const unsigned char *>(PACKAGE_VERSION),
+ APT_ARRAY_SIZE(PACKAGE_VERSION));
- adler = hash32(adler,
- reinterpret_cast<const unsigned char *>(&header),
- sizeof(header));
+ XXH3_64bits_update(state,
+ reinterpret_cast<const unsigned char *>(&header),
+ sizeof(header));
if (Map.Size() > sizeof(header)) {
- adler = hash32(adler,
- static_cast<const unsigned char *>(GetMap().Data()) + sizeof(header),
- GetMap().Size() - sizeof(header));
+ XXH3_64bits_update(state,
+ static_cast<const unsigned char *>(GetMap().Data()) + sizeof(header),
+ GetMap().Size() - sizeof(header));
}
- return adler;
+ auto const digest = XXH3_64bits_digest(state);
+ XXH3_freeState(state);
+ return digest & 0xFFFFFFFF;
}
/*}}}*/
// Cache::FindPkg - Locate a package by name /*{{{*/