From: David Kalnischkies Date: Wed, 15 Jul 2015 12:36:16 +0000 (+0200) Subject: use a smaller type for flags storage in the cache X-Git-Tag: 1.1.exp9~92 X-Git-Url: https://git.saurik.com/apt.git/commitdiff_plain/dfe66c72ffc010e019e96b35154e1ad4ab506a6e use a smaller type for flags storage in the cache We store very few flags in the cache, so keeping storage space for 8 is enough for all of them and still leaves a few unused bits remaining for future extensions without wasting bytes for nothing. Git-Dch: Ignore --- diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 2348cca2d..5034ee38a 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -50,27 +50,29 @@ using std::string; /* Simply initialize the header */ pkgCache::Header::Header() { - Signature = 0x98FE76DC; - +#define APT_HEADER_SET(X,Y) X = Y; static_assert(std::numeric_limits::max() > Y, "Size violation detected in pkgCache::Header") + APT_HEADER_SET(Signature, 0x98FE76DC); + /* Whenever the structures change the major version should be bumped, whenever the generator changes the minor version should be bumped. */ - MajorVersion = 10; - MinorVersion = 0; - Dirty = false; - - HeaderSz = sizeof(pkgCache::Header); - GroupSz = sizeof(pkgCache::Group); - PackageSz = sizeof(pkgCache::Package); - ReleaseFileSz = sizeof(pkgCache::ReleaseFile); - PackageFileSz = sizeof(pkgCache::PackageFile); - VersionSz = sizeof(pkgCache::Version); - DescriptionSz = sizeof(pkgCache::Description); - DependencySz = sizeof(pkgCache::Dependency); - DependencyDataSz = sizeof(pkgCache::DependencyData); - ProvidesSz = sizeof(pkgCache::Provides); - VerFileSz = sizeof(pkgCache::VerFile); - DescFileSz = sizeof(pkgCache::DescFile); - + APT_HEADER_SET(MajorVersion, 10); + APT_HEADER_SET(MinorVersion, 0); + APT_HEADER_SET(Dirty, false); + + APT_HEADER_SET(HeaderSz, sizeof(pkgCache::Header)); + APT_HEADER_SET(GroupSz, sizeof(pkgCache::Group)); + APT_HEADER_SET(PackageSz, sizeof(pkgCache::Package)); + APT_HEADER_SET(ReleaseFileSz, sizeof(pkgCache::ReleaseFile)); + APT_HEADER_SET(PackageFileSz, sizeof(pkgCache::PackageFile)); + APT_HEADER_SET(VersionSz, sizeof(pkgCache::Version)); + APT_HEADER_SET(DescriptionSz, sizeof(pkgCache::Description)); + APT_HEADER_SET(DependencySz, sizeof(pkgCache::Dependency)); + APT_HEADER_SET(DependencyDataSz, sizeof(pkgCache::DependencyData)); + APT_HEADER_SET(ProvidesSz, sizeof(pkgCache::Provides)); + APT_HEADER_SET(VerFileSz, sizeof(pkgCache::VerFile)); + APT_HEADER_SET(DescFileSz, sizeof(pkgCache::DescFile)); +#undef APT_HEADER_SET + GroupCount = 0; PackageCount = 0; VersionCount = 0; @@ -84,7 +86,7 @@ pkgCache::Header::Header() ProvidesCount = 0; MaxVerFileSize = 0; MaxDescFileSize = 0; - + FileList = 0; RlsFileList = 0; VerSysName = 0; diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 3fa815c15..fba692982 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -97,6 +97,9 @@ typedef uint16_t map_fileid_t; typedef uint32_t map_pointer_t; // same as the previous, but documented to be to a string item typedef map_pointer_t map_stringitem_t; +// we have only a small amount of flags for each item +typedef uint8_t map_flags_t; +typedef uint8_t map_number_t; class pkgVersioningSystem; class pkgCache /*{{{*/ @@ -259,10 +262,10 @@ struct pkgCache::Header This must contain the hex value 0x98FE76DC which is designed to verify that the system loading the image has the same byte order and byte size as the system saving the image */ - unsigned long Signature; + uint32_t Signature; /** These contain the version of the cache file */ - short MajorVersion; - short MinorVersion; + map_number_t MajorVersion; + map_number_t MinorVersion; /** \brief indicates if the cache should be erased Dirty is true if the cache file was opened for reading, the client @@ -277,18 +280,18 @@ struct pkgCache::Header If any of the size values do not exactly match what the client expects then the client should refuse the load the file. */ - unsigned short HeaderSz; - unsigned short GroupSz; - unsigned short PackageSz; - unsigned short ReleaseFileSz; - unsigned short PackageFileSz; - unsigned short VersionSz; - unsigned short DescriptionSz; - unsigned short DependencySz; - unsigned short DependencyDataSz; - unsigned short ProvidesSz; - unsigned short VerFileSz; - unsigned short DescFileSz; + uint16_t HeaderSz; + map_number_t GroupSz; + map_number_t PackageSz; + map_number_t ReleaseFileSz; + map_number_t PackageFileSz; + map_number_t VersionSz; + map_number_t DescriptionSz; + map_number_t DependencySz; + map_number_t DependencyDataSz; + map_number_t ProvidesSz; + map_number_t VerFileSz; + map_number_t DescFileSz; /** \brief Structure counts @@ -346,8 +349,8 @@ struct pkgCache::Header In the PkgHashTable is it possible that multiple packages have the same name - these packages are stored as a sequence in the list. The size of both tables is the same. */ - unsigned int HashTableSize; - unsigned int GetHashTableSize() const { return HashTableSize; } + uint32_t HashTableSize; + uint32_t GetHashTableSize() const { return HashTableSize; } void SetHashTableSize(unsigned int const sz) { HashTableSize = sz; } map_pointer_t GetArchitectures() const { return Architectures; } void SetArchitectures(map_pointer_t const idx) { Architectures = idx; } @@ -437,15 +440,15 @@ struct pkgCache::Package // Install/Remove/Purge etc /** \brief state that the user wishes the package to be in */ - unsigned char SelectedState; // What + map_number_t SelectedState; // What /** \brief installation state of the package This should be "ok" but in case the installation failed it will be different. */ - unsigned char InstState; // Flags + map_number_t InstState; // Flags /** \brief indicates if the package is installed */ - unsigned char CurrentState; // State + map_number_t CurrentState; // State /** \brief unique sequel ID @@ -455,7 +458,7 @@ struct pkgCache::Package this to track which packages have been emitted already. */ map_id_t ID; /** \brief some useful indicators of the package's state */ - unsigned long Flags; + map_flags_t Flags; }; /*}}}*/ // Release File structure /*{{{*/ @@ -489,7 +492,7 @@ struct pkgCache::ReleaseFile time_t mtime; /** @TODO document PackageFile::Flags */ - unsigned long Flags; + map_flags_t Flags; // Linked list /** \brief Link to the next ReleaseFile in the Cache */ @@ -528,7 +531,7 @@ struct pkgCache::PackageFile time_t mtime; /** @TODO document PackageFile::Flags */ - unsigned long Flags; + map_flags_t Flags; // Linked list /** \brief Link to the next PackageFile in the Cache */ @@ -599,7 +602,7 @@ struct pkgCache::Version Flags used are defined in pkgCache::Version::VerMultiArch */ - unsigned char MultiArch; + map_number_t MultiArch; /** \brief references all the PackageFile's that this version came from @@ -635,7 +638,7 @@ struct pkgCache::Version /** \brief unique sequel ID */ map_id_t ID; /** \brief parsed priority value */ - unsigned char Priority; + map_number_t Priority; }; /*}}}*/ // Description structure /*{{{*/ @@ -682,11 +685,11 @@ struct pkgCache::DependencyData map_pointer_t Package; // Package /** \brief Dependency type - Depends, Recommends, Conflicts, etc */ - unsigned char Type; + map_number_t Type; /** \brief comparison operator specified on the depends line If the high bit is set then it is a logical OR with the previous record. */ - unsigned char CompareOp; + map_flags_t CompareOp; map_pointer_t NextData; }; diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 213a413cb..253b1b7a3 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -579,6 +579,34 @@ bool pkgTagSection::FindB(const char *Tag, bool const &Default) const // TagSection::FindFlag - Locate a yes/no type flag /*{{{*/ // --------------------------------------------------------------------- /* The bits marked in Flag are masked on/off in Flags */ +bool pkgTagSection::FindFlag(const char * const Tag, uint8_t &Flags, + uint8_t const Flag) const +{ + const char *Start; + const char *Stop; + if (Find(Tag,Start,Stop) == false) + return true; + return FindFlag(Flags, Flag, Start, Stop); +} +bool pkgTagSection::FindFlag(uint8_t &Flags, uint8_t const Flag, + char const* const Start, char const* const Stop) +{ + switch (StringToBool(string(Start, Stop))) + { + case 0: + Flags &= ~Flag; + return true; + + case 1: + Flags |= Flag; + return true; + + default: + _error->Warning("Unknown flag value: %s",string(Start,Stop).c_str()); + return true; + } + return true; +} bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const { diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index 847a799f4..19c07595e 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -56,6 +56,10 @@ class pkgTagSection signed int FindI(const char *Tag,signed long Default = 0) const; bool FindB(const char *Tag, bool const &Default = false) const; unsigned long long FindULL(const char *Tag, unsigned long long const &Default = 0) const; + bool FindFlag(const char * const Tag,uint8_t &Flags, + uint8_t const Flag) const; + bool static FindFlag(uint8_t &Flags, uint8_t const Flag, + const char* const Start, const char* const Stop); bool FindFlag(const char *Tag,unsigned long &Flags, unsigned long Flag) const; bool static FindFlag(unsigned long &Flags, unsigned long Flag,