Bläddra i källkod

pkgCacheGenerator: Use StringView for toString

This removes some minor overhead.

Gbp-Dch: ignore
Julian Andres Klode 10 år sedan
förälder
incheckning
dd592790c8
2 ändrade filer med 12 tillägg och 7 borttagningar
  1. 5 5
      apt-pkg/pkgcachegen.cc
  2. 7 2
      apt-pkg/pkgcachegen.h

+ 5 - 5
apt-pkg/pkgcachegen.cc

@@ -514,7 +514,7 @@ bool pkgCacheGenerator::NewGroup(pkgCache::GrpIterator &Grp, StringView Name)
       return false;
 
    Grp = pkgCache::GrpIterator(Cache, Cache.GrpP + Group);
-   map_stringitem_t const idxName = StoreString(PKGNAME, Name.to_string());
+   map_stringitem_t const idxName = StoreString(PKGNAME, Name);
    if (unlikely(idxName == 0))
       return false;
    Grp->Name = idxName;
@@ -555,7 +555,7 @@ bool pkgCacheGenerator::NewPackage(pkgCache::PkgIterator &Pkg, StringView Name,
    APT_IGNORE_DEPRECATED(Pkg->Name = Grp->Name;)
    Pkg->Group = Grp.Index();
    // all is mapped to the native architecture
-   map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : StoreString(MIXED, Arch.to_string());
+   map_stringitem_t const idxArch = (Arch == "all") ? Cache.HeaderP->Architecture : StoreString(MIXED, Arch);
    if (unlikely(idxArch == 0))
       return false;
    Pkg->Arch = idxArch;
@@ -1019,7 +1019,7 @@ bool pkgCacheListParser::NewDepends(pkgCache::VerIterator &Ver,
 
       if (idxVersion == 0)
       {
-	 idxVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version.to_string());
+	 idxVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version);
 	 if (unlikely(idxVersion == 0))
 	    return false;
       }
@@ -1088,7 +1088,7 @@ bool pkgCacheListParser::NewProvides(pkgCache::VerIterator &Ver,
 
    map_stringitem_t idxProvideVersion = 0;
    if (Version.empty() == false) {
-      idxProvideVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version.to_string());
+      idxProvideVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version);
       if (unlikely(idxProvideVersion == 0))
 	 return false;
    }
@@ -1133,7 +1133,7 @@ bool pkgCacheListParser::NewProvidesAllArch(pkgCache::VerIterator &Ver, StringVi
    {
       map_stringitem_t idxProvideVersion = 0;
       if (Version.empty() == false) {
-	 idxProvideVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version.to_string());
+	 idxProvideVersion = StoreString(pkgCacheGenerator::VERSIONNUMBER, Version);
 	 if (unlikely(idxProvideVersion == 0))
 	    return false;
       }

+ 7 - 2
apt-pkg/pkgcachegen.h

@@ -104,7 +104,10 @@ class APT_HIDDEN pkgCacheGenerator					/*{{{*/
 
    enum StringType { MIXED, PKGNAME, VERSIONNUMBER, SECTION };
    map_stringitem_t StoreString(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());};
+
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   inline map_stringitem_t StoreString(enum StringType const type, APT::StringView S) {return StoreString(type, S.data(),S.length());};
+#endif
 
    void DropProgress() {Progress = 0;};
    bool SelectFile(const std::string &File,pkgIndexFile const &Index, std::string const &Architecture, std::string const &Component, unsigned long Flags = 0);
@@ -156,8 +159,10 @@ class APT_HIDDEN pkgCacheListParser
 
    protected:
 
-   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);};
+#ifdef APT_PKG_EXPOSE_STRING_VIEW
+   inline map_stringitem_t StoreString(pkgCacheGenerator::StringType const type, APT::StringView S) {return Owner->StoreString(type, S);};
+#endif
 
    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);};