diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-06-20 21:33:56 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-09-27 00:09:35 +0200 |
commit | 78a5476f3177a2a74ae51a1878c26ca322a25003 (patch) | |
tree | ce7572f671deaf5e07e01fff64432daaf97e4bd5 /apt-pkg/pkgcachegen.h | |
parent | a3a91fd7bab34983a008854728baf26034d4033e (diff) |
drop stored StringItems in favor of in-memory mappings
Strings like Section names or architectures are needed vary often.
Instead of writing them each time we need them, we deploy sharing for
these special strings. Until now, this was done with a linked list of
strings in which we would search, which was stored in the cache.
It turns out we can do this just as well in memory as well with a bunch
of std::map's.
In memory means here that it isn't available anymore if we have a partly
invalid cache, but that isn't much of a problem in practice as the
status file is compared to the other files we parse very small and includes
mostly duplicates, so the space we would gain by storing is more or less
equal to the size of the stored linked list…
Diffstat (limited to 'apt-pkg/pkgcachegen.h')
-rw-r--r-- | apt-pkg/pkgcachegen.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 42da7b12d..84777b912 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -27,6 +27,7 @@ #include <vector> #include <string> +#include <map> class FileFd; class pkgSourceList; @@ -36,13 +37,16 @@ class pkgIndexFile; class pkgCacheGenerator /*{{{*/ { private: - - pkgCache::StringItem *UniqHash[26]; APT_HIDDEN map_stringitem_t WriteStringInMap(std::string const &String) { return WriteStringInMap(String.c_str()); }; APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String); APT_HIDDEN map_stringitem_t WriteStringInMap(const char *String, const unsigned long &Len); APT_HIDDEN map_pointer_t AllocateInMap(const unsigned long &size); + std::map<std::string,map_stringitem_t> strMixed; + std::map<std::string,map_stringitem_t> strSections; + std::map<std::string,map_stringitem_t> strPkgNames; + std::map<std::string,map_stringitem_t> strVersions; + public: class ListParser; @@ -91,8 +95,9 @@ class pkgCacheGenerator /*{{{*/ public: - map_stringitem_t WriteUniqString(const char *S,unsigned int const Size); - inline map_stringitem_t WriteUniqString(const std::string &S) {return WriteUniqString(S.c_str(),S.length());}; + enum StringType { MIXED, PKGNAME, VERSION, SECTION }; + map_stringitem_t StoreString(enum StringType const type, const char * S, unsigned int const Size); + inline map_stringitem_t StoreString(enum StringType const type, const std::string &S) {return StoreString(type, S.c_str(),S.length());}; void DropProgress() {Progress = 0;}; bool SelectFile(const std::string &File,const std::string &Site,pkgIndexFile const &Index, @@ -145,8 +150,9 @@ class pkgCacheGenerator::ListParser protected: - inline map_stringitem_t WriteUniqString(std::string S) {return Owner->WriteUniqString(S);}; - inline map_stringitem_t WriteUniqString(const char *S,unsigned int Size) {return Owner->WriteUniqString(S,Size);}; + inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, std::string const &S) {return Owner->StoreString(type, S);}; + inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, const char *S,unsigned int Size) {return Owner->StoreString(type, S, Size);}; + inline map_stringitem_t WriteString(const std::string &S) {return Owner->WriteStringInMap(S);}; inline map_stringitem_t WriteString(const char *S,unsigned int Size) {return Owner->WriteStringInMap(S,Size);}; bool NewDepends(pkgCache::VerIterator &Ver,const std::string &Package, const std::string &Arch, |