#include<config.h>
#include <apt-pkg/tagfile.h>
+#include <apt-pkg/tagfile-keys.h>
#include <apt-pkg/error.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/fileutl.h>
pkgTagSectionPrivate::TagData lastTagData(0);
lastTagData.EndTag = 0;
- unsigned long lastTagHash = 0;
+ Key lastTagKey = Key::Unknown;
+ unsigned int lastTagHash = 0;
while (Stop < End)
{
TrimRecord(true,End);
// store the last found tag
if (lastTagData.EndTag != 0)
{
- if (BetaIndexes[lastTagHash] != 0)
- lastTagData.NextInBucket = BetaIndexes[lastTagHash];
- APT_IGNORE_DEPRECATED_PUSH
- BetaIndexes[lastTagHash] = TagCount;
- APT_IGNORE_DEPRECATED_POP
+ if (lastTagKey != Key::Unknown) {
+ AlphaIndexes[static_cast<size_t>(lastTagKey)] = TagCount;
+ } else {
+ if (BetaIndexes[lastTagHash] != 0)
+ lastTagData.NextInBucket = BetaIndexes[lastTagHash];
+ APT_IGNORE_DEPRECATED_PUSH
+ BetaIndexes[lastTagHash] = TagCount;
+ APT_IGNORE_DEPRECATED_POP
+ }
d->Tags.push_back(lastTagData);
}
;
++EndTag;
lastTagData.EndTag = EndTag - Section;
- lastTagHash = BetaHash(Stop, EndTag - Stop);
+ lastTagKey = pkgTagHash(Stop, EndTag - Stop);
+ if (lastTagKey == Key::Unknown)
+ lastTagHash = BetaHash(Stop, EndTag - Stop);
// find the beginning of the value
Stop = Colon + 1;
for (; Stop < End && isspace_ascii(*Stop) != 0; ++Stop)
{
if (lastTagData.EndTag != 0)
{
- if (BetaIndexes[lastTagHash] != 0)
- lastTagData.NextInBucket = BetaIndexes[lastTagHash];
- APT_IGNORE_DEPRECATED(BetaIndexes[lastTagHash] = TagCount;)
+ if (lastTagKey != Key::Unknown) {
+ AlphaIndexes[static_cast<size_t>(lastTagKey)] = TagCount;
+ } else {
+ if (BetaIndexes[lastTagHash] != 0)
+ lastTagData.NextInBucket = BetaIndexes[lastTagHash];
+ APT_IGNORE_DEPRECATED(BetaIndexes[lastTagHash] = TagCount;)
+ }
d->Tags.push_back(lastTagData);
}
// TagSection::Find - Locate a tag /*{{{*/
// ---------------------------------------------------------------------
/* This searches the section for a tag that matches the given string. */
+bool pkgTagSection::Find(Key key,unsigned int &Pos) const
+{
+ auto Bucket = AlphaIndexes[static_cast<size_t>(key)];
+ Pos = Bucket - 1;
+ return Bucket != 0;
+}
bool pkgTagSection::Find(StringView TagView,unsigned int &Pos) const
{
const char * const Tag = TagView.data();
size_t const Length = TagView.length();
+ auto key = pkgTagHash(Tag, Length);
+ if (key != Key::Unknown)
+ return Find(key, Pos);
+
unsigned int Bucket = BetaIndexes[BetaHash(Tag, Length)];
if (Bucket == 0)
return false;
{
unsigned int Pos;
return Find(Tag, Pos) && FindInternal(Pos, Start, End);
+}
+bool pkgTagSection::Find(Key key,const char *&Start,
+ const char *&End) const
+{
+ unsigned int Pos;
+ return Find(key, Pos) && FindInternal(Pos, Start, End);
}
/*}}}*/
// TagSection::FindS - Find a string /*{{{*/
if (Find(Tag,Start,End) == false)
return StringView();
return StringView(Start, End - Start);
+}
+StringView pkgTagSection::Find(Key key) const
+{
+ const char *Start;
+ const char *End;
+ if (Find(key,Start,End) == false)
+ return StringView();
+ return StringView(Start, End - Start);
}
/*}}}*/
// TagSection::FindRawS - Find a string /*{{{*/
{
unsigned int Pos;
return Find(Tag, Pos) ? FindRawInternal(Pos) : "";
+}
+StringView pkgTagSection::FindRaw(Key key) const
+{
+ unsigned int Pos;
+ return Find(key, Pos) ? FindRawInternal(Pos) : "";
}
/*}}}*/
// TagSection::FindI - Find an integer /*{{{*/
return Default;
return Result;
}
+signed int pkgTagSection::FindI(Key key,signed long Default) const
+{
+ unsigned int Pos;
+
+ return Find(key, Pos) ? FindIInternal(Pos) : Default;
+}
signed int pkgTagSection::FindI(StringView Tag,signed long Default) const
{
unsigned int Pos;
return Default;
return Result;
}
+unsigned long long pkgTagSection::FindULL(Key key, unsigned long long const &Default) const
+{
+ unsigned int Pos;
+
+ return Find(key, Pos) ? FindULLInternal(Pos, Default) : Default;
+}
unsigned long long pkgTagSection::FindULL(StringView Tag, unsigned long long const &Default) const
{
unsigned int Pos;
return Default;
return StringToBool(string(Start, Stop));
}
+bool pkgTagSection::FindB(Key key, bool Default) const
+{
+ unsigned int Pos;
+ return Find(key, Pos) ? FindBInternal(Pos, Default): Default;
+}
bool pkgTagSection::FindB(StringView Tag, bool Default) const
{
unsigned int Pos;
return true;
return FindFlag(Flags, Flag, Start, Stop);
}
+bool pkgTagSection::FindFlag(Key key, uint8_t &Flags,
+ uint8_t const Flag) const
+{
+ unsigned int Pos;
+ if (Find(key,Pos) == false)
+ return true;
+ return FindFlagInternal(Pos, Flags, Flag);
+}
bool pkgTagSection::FindFlag(StringView Tag, uint8_t &Flags,
uint8_t const Flag) const
{
return true;
return FindFlag(Flags, Flag, Start, Stop);
}
+bool pkgTagSection::FindFlag(Key key,unsigned long &Flags,
+ unsigned long Flag) const
+{
+ unsigned int Pos;
+ return Find(key, Pos) ? FindFlagInternal(Pos, Flags, Flag) : true;
+}
bool pkgTagSection::FindFlag(StringView Tag,unsigned long &Flags,
unsigned long Flag) const
{
std::string FindS(const char *Tag) const;
std::string FindRawS(const char *Tag) const;
+ // Functions for lookup with a perfect hash function
+ enum class Key;
+ APT_HIDDEN bool Find(Key key,const char *&Start, const char *&End) const;
+ APT_HIDDEN bool Find(Key key,unsigned int &Pos) const;
+ APT_HIDDEN signed int FindI(Key key,signed long Default = 0) const;
+ APT_HIDDEN bool FindB(Key key, bool Default = false) const;
+ APT_HIDDEN unsigned long long FindULL(Key key, unsigned long long const &Default = 0) const;
+ APT_HIDDEN bool FindFlag(Key key,uint8_t &Flags, uint8_t const Flag) const;
+ APT_HIDDEN bool FindFlag(Key key,unsigned long &Flags, unsigned long Flag) const;
+ APT_HIDDEN bool Exists(Key key) const;
#ifdef APT_PKG_EXPOSE_STRING_VIEW
+ APT_HIDDEN APT::StringView Find(Key key) const;
+ APT_HIDDEN APT::StringView FindRaw(Key key) const;
APT_HIDDEN bool Find(APT::StringView Tag,const char *&Start, const char *&End) const;
APT_HIDDEN bool Find(APT::StringView Tag,unsigned int &Pos) const;
APT_HIDDEN APT::StringView Find(APT::StringView Tag) const;