diff options
author | David Kalnischkies <david@kalnischkies.de> | 2016-01-26 23:18:05 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2016-01-26 23:18:05 +0100 |
commit | 8efd5947bf7de0fc3db51b4871bcf3522018761d (patch) | |
tree | 698e9f3468b85227ca9a0fa7969a0b412baec361 /apt-pkg | |
parent | 02ceb810fe0de9b267a8b6a302505967afce6b5a (diff) |
convert Version() and Architecture() to APT::StringView
Part of hidden classes, so conversion is abi-free.
Git-Dch: Ignore
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/deb/deblistparser.cc | 28 | ||||
-rw-r--r-- | apt-pkg/deb/deblistparser.h | 12 | ||||
-rw-r--r-- | apt-pkg/pkgcachegen.cc | 27 | ||||
-rw-r--r-- | apt-pkg/pkgcachegen.h | 18 |
4 files changed, 47 insertions, 38 deletions
diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 86fd5dc54..860aa3bc2 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -72,9 +72,9 @@ string debListParser::Package() { // ListParser::Architecture - Return the package arch /*{{{*/ // --------------------------------------------------------------------- /* This will return the Architecture of the package this section describes */ -string debListParser::Architecture() { +APT::StringView debListParser::Architecture() { auto const Arch = Section.Find("Architecture"); - return Arch.empty() ? "none" : Arch.to_string(); + return Arch.empty() ? "none" : Arch; } /*}}}*/ // ListParser::ArchitectureAll /*{{{*/ @@ -89,9 +89,9 @@ bool debListParser::ArchitectureAll() { /* This is to return the string describing the version in debian form, epoch:upstream-release. If this returns the blank string then the entry is assumed to only describe package properties */ -string debListParser::Version() +APT::StringView debListParser::Version() { - return Section.Find("Version").to_string(); + return Section.Find("Version"); } /*}}}*/ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ @@ -160,7 +160,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) const char * const Close = (const char * const) memchr(Open, ')', Stop - Open); if (likely(Close != NULL)) { - std::string const version(Open + 1, (Close - Open) - 1); + APT::StringView const version(Open + 1, (Close - Open) - 1); if (version != Ver.VerStr()) { map_stringitem_t const idx = StoreString(pkgCacheGenerator::VERSIONNUMBER, version); @@ -171,7 +171,7 @@ bool debListParser::NewVersion(pkgCache::VerIterator &Ver) Stop = Space; } - std::string const pkgname(Start, Stop - Start); + APT::StringView const pkgname(Start, Stop - Start); if (pkgname != G.Name()) { for (pkgCache::PkgIterator P = G.PackageList(); P.end() == false; P = G.NextPkg(P)) @@ -651,7 +651,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, ++I; } - std::string arch(I, End); + std::string const arch(I, End); if (arch.empty() == false && matchesArch(arch.c_str()) == true) { Found = true; @@ -733,8 +733,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, ++I; } - std::string restriction(I, End); - + std::string const restriction(I, End); if (restriction.empty() == false && profiles.empty() == false && std::find(profiles.begin(), profiles.end(), restriction) != profiles.end()) { @@ -825,12 +824,13 @@ bool debListParser::ParseDepends(pkgCache::VerIterator &Ver, { // Such dependencies are not supposed to be accepted … // … but this is probably the best thing to do anyway - std::string Pkg; if (Package.substr(found + 1) == "native") - Pkg = Package.substr(0, found).to_string() + ':' + Ver.Cache()->NativeArch(); - else - Pkg = Package.to_string(); - if (NewDepends(Ver, Pkg, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false) + { + std::string const Pkg = Package.substr(0, found).to_string() + ':' + Ver.Cache()->NativeArch(); + if (NewDepends(Ver, Pkg, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false) + return false; + } + else if (NewDepends(Ver, Package, "any", Version, Op | pkgCache::Dep::ArchSpecific, Type) == false) return false; } diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index 1c5275e0a..a78312f9d 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -69,9 +69,11 @@ class APT_HIDDEN debListParser : public pkgCacheListParser // These all operate against the current section virtual std::string Package() APT_OVERRIDE; - virtual std::string Architecture() APT_OVERRIDE; virtual bool ArchitectureAll() APT_OVERRIDE; - virtual std::string Version() APT_OVERRIDE; +#ifdef APT_PKG_EXPOSE_STRING_VIEW + virtual APT::StringView Architecture() APT_OVERRIDE; + virtual APT::StringView Version() APT_OVERRIDE; +#endif virtual bool NewVersion(pkgCache::VerIterator &Ver) APT_OVERRIDE; virtual std::vector<std::string> AvailableDescriptionLanguages() APT_OVERRIDE; virtual MD5SumValue Description_md5() APT_OVERRIDE; @@ -128,9 +130,11 @@ class APT_HIDDEN debDebFileParser : public debListParser class APT_HIDDEN debTranslationsParser : public debListParser { public: +#ifdef APT_PKG_EXPOSE_STRING_VIEW // a translation can never be a real package - virtual std::string Architecture() APT_OVERRIDE { return ""; } - virtual std::string Version() APT_OVERRIDE { return ""; } + virtual APT::StringView Architecture() APT_OVERRIDE { return ""; } + virtual APT::StringView Version() APT_OVERRIDE { return ""; } +#endif debTranslationsParser(FileFd *File) : debListParser(File) {}; diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 120b0c414..a48fe7946 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -40,8 +40,8 @@ #include <unistd.h> #include <apti18n.h> - -template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>; /*}}}*/ + /*}}}*/ +template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>; typedef std::vector<pkgIndexFile *>::iterator FileIterator; template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap; @@ -236,8 +236,10 @@ bool pkgCacheGenerator::MergeList(ListParser &List, if (Counter % 100 == 0 && Progress != 0) Progress->Progress(List.Offset()); - string Arch = List.Architecture(); - string const Version = List.Version(); + APT::StringView Arch = List.Architecture(); + Dynamic<APT::StringView> DynArch(Arch); + APT::StringView Version = List.Version(); + Dynamic<APT::StringView> DynVersion(Version); if (Version.empty() == true && Arch.empty() == true) { // package descriptions @@ -348,7 +350,7 @@ bool pkgCacheGenerator::MergeListPackage(ListParser &List, pkgCache::PkgIterator /*}}}*/ // CacheGenerator::MergeListVersion /*{{{*/ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, - std::string const &Version, pkgCache::VerIterator* &OutVer) + APT::StringView const &Version, pkgCache::VerIterator* &OutVer) { pkgCache::VerIterator Ver = Pkg.VersionList(); Dynamic<pkgCache::VerIterator> DynVer(Ver); @@ -363,7 +365,9 @@ bool pkgCacheGenerator::MergeListVersion(ListParser &List, pkgCache::PkgIterator int Res = 1; for (; Ver.end() == false; LastVer = &Ver->NextVer, ++Ver) { - Res = Cache.VS->CmpVersion(Version,Ver.VerStr()); + char const * const VerStr = Ver.VerStr(); + Res = Cache.VS->DoCmpVersion(Version.data(), Version.data() + Version.length(), + VerStr, VerStr + strlen(VerStr)); // Version is higher as current version - insert here if (Res > 0) break; @@ -709,9 +713,8 @@ bool pkgCacheGenerator::AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, pkgCache::VerIterator &V) { - // copy P.Arch() into a string here as a cache remap - // in NewDepends() later may alter the pointer location - string Arch = P.Arch() == NULL ? "" : P.Arch(); + APT::StringView Arch = P.Arch() == NULL ? "" : P.Arch(); + Dynamic<APT::StringView> DynArch(Arch); map_pointer_t *OldDepLast = NULL; /* MultiArch handling introduces a lot of implicit Dependencies: - MultiArch: same → Co-Installable if they have the same version @@ -812,7 +815,7 @@ bool pkgCacheGenerator::NewFileVer(pkgCache::VerIterator &Ver, // --------------------------------------------------------------------- /* This puts a version structure in the linked list */ map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, - const string &VerStr, + APT::StringView const &VerStr, map_pointer_t const ParentPkg, unsigned short const Hash, map_pointer_t const Next) @@ -841,8 +844,8 @@ map_pointer_t pkgCacheGenerator::NewVersion(pkgCache::VerIterator &Ver, continue; for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; ++V) { - int const cmp = strcmp(V.VerStr(), VerStr.c_str()); - if (cmp == 0) + int const cmp = strncmp(V.VerStr(), VerStr.data(), VerStr.length()); + if (cmp == 0 && V.VerStr()[VerStr.length()] == '\0') { Ver->VerStr = V->VerStr; return Version; diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index a3de37a60..d0ae67997 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -114,17 +114,15 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/ #ifdef APT_PKG_EXPOSE_STRING_VIEW 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 Next); #endif bool NewFileVer(pkgCache::VerIterator &Ver,ListParser &List); bool NewFileDesc(pkgCache::DescIterator &Desc,ListParser &List); bool NewDepends(pkgCache::PkgIterator &Pkg, pkgCache::VerIterator &Ver, map_pointer_t const Version, uint8_t const Op, uint8_t const Type, map_pointer_t* &OldDepLast); - map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr,map_pointer_t const Next) APT_DEPRECATED - { return NewVersion(Ver, VerStr, 0, 0, Next); } - map_pointer_t NewVersion(pkgCache::VerIterator &Ver,const std::string &VerStr, - map_pointer_t const ParentPkg, unsigned short const Hash, - map_pointer_t const Next); map_pointer_t NewDescription(pkgCache::DescIterator &Desc,const std::string &Lang,const MD5SumValue &md5sum,map_stringitem_t const idxmd5str); bool NewProvides(pkgCache::VerIterator &Ver, pkgCache::PkgIterator &Pkg, map_stringitem_t const ProvidesVersion, uint8_t const Flags); @@ -163,8 +161,10 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/ void * const d; APT_HIDDEN bool MergeListGroup(ListParser &List, std::string const &GrpName); APT_HIDDEN bool MergeListPackage(ListParser &List, pkgCache::PkgIterator &Pkg); +#ifdef APT_PKG_EXPOSE_STRING_VIEW APT_HIDDEN bool MergeListVersion(ListParser &List, pkgCache::PkgIterator &Pkg, - std::string const &Version, pkgCache::VerIterator* &OutVer); + APT::StringView const &Version, pkgCache::VerIterator* &OutVer); +#endif APT_HIDDEN bool AddImplicitDepends(pkgCache::GrpIterator &G, pkgCache::PkgIterator &P, pkgCache::VerIterator &V); @@ -209,9 +209,11 @@ class APT_HIDDEN pkgCacheListParser // These all operate against the current section virtual std::string Package() = 0; - virtual std::string Architecture() = 0; virtual bool ArchitectureAll() = 0; - virtual std::string Version() = 0; +#ifdef APT_PKG_EXPOSE_STRING_VIEW + virtual APT::StringView Architecture() = 0; + virtual APT::StringView Version() = 0; +#endif virtual bool NewVersion(pkgCache::VerIterator &Ver) = 0; virtual std::vector<std::string> AvailableDescriptionLanguages() = 0; virtual MD5SumValue Description_md5() = 0; |