summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgcachegen.h
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-01-08 01:27:01 +0100
committerJulian Andres Klode <jak@debian.org>2016-01-08 01:30:18 +0100
commit869700d839a1695fe00734592bd504d59386e4b9 (patch)
tree3ad6f069d50aa4d44cc733c11b1231d04df4856b /apt-pkg/pkgcachegen.h
parent57590d3c6e6b055402c938c3baebf1d872c58f7e (diff)
pkgCacheGenerator::StoreString: Get rid of std::string
Instead of storing a string -> map_stringitem_t mapping, create our own data type that can point to either a normal string or a string inside the cache. This avoids the creation of any string and improves performance slightly (about 4%).
Diffstat (limited to 'apt-pkg/pkgcachegen.h')
-rw-r--r--apt-pkg/pkgcachegen.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h
index e4760d44d..d83ea6a25 100644
--- a/apt-pkg/pkgcachegen.h
+++ b/apt-pkg/pkgcachegen.h
@@ -27,7 +27,7 @@
#include <vector>
#include <string>
#if __cplusplus >= 201103L
-#include <unordered_map>
+#include <unordered_set>
#endif
#ifdef APT_PKG_EXPOSE_STRING_VIEW
#include <apt-pkg/string_view.h>
@@ -48,10 +48,34 @@ class APT_HIDDEN pkgCacheGenerator /*{{{*/
// Dirty hack for public users that do not use C++11 yet
#if __cplusplus >= 201103L
- std::unordered_map<std::string,map_stringitem_t> strMixed;
- std::unordered_map<std::string,map_stringitem_t> strSections;
- std::unordered_map<std::string,map_stringitem_t> strPkgNames;
- std::unordered_map<std::string,map_stringitem_t> strVersions;
+ struct string_pointer {
+ const char *data_;
+ size_t size;
+ pkgCacheGenerator *generator;
+ map_stringitem_t item;
+
+ const char *data() const {
+ return data_ != nullptr ? data_ : static_cast<char*>(generator->Map.Data()) + item;
+ }
+
+ bool operator ==(string_pointer const &other) const {
+ return size == other.size && memcmp(data(), other.data(), size) == 0;
+ }
+ };
+ struct hash {
+ uint32_t operator()(string_pointer const &that) const {
+ uint32_t Hash = 5381;
+ const char * const end = that.data() + that.size;
+ for (const char *I = that.data(); I != end; ++I)
+ Hash = 33 * Hash + tolower_ascii((signed char)*I);
+ return Hash;
+ }
+ };
+
+ std::unordered_set<string_pointer, hash> strMixed;
+ std::unordered_set<string_pointer, hash> strPkgNames;
+ std::unordered_set<string_pointer, hash> strVersions;
+ std::unordered_set<string_pointer, hash> strSections;
#endif
friend class pkgCacheListParser;