summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2016-09-27 18:59:11 +0200
committerJulian Andres Klode <jak@debian.org>2016-11-22 22:58:19 +0100
commitf378b41f9ab2493bcbc5892d482b18826b0b84c0 (patch)
tree70f6a9235860f9f04b1b55b110e5412f1c601037 /apt-pkg/contrib
parentf903069c139df58d1ba855f7cf02c4a2d4e51dc3 (diff)
Compare size before data when ordering cache bucket entries
This has the effect of significantly reducing actual string comparisons, and should improve the performance of FindGrp a bit, although it's hardly measureable (callgrind says it uses 10% instructions less now).
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/string_view.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h
index f158ef8d6..c504edd27 100644
--- a/apt-pkg/contrib/string_view.h
+++ b/apt-pkg/contrib/string_view.h
@@ -112,6 +112,17 @@ public:
constexpr size_t length() const { return size_; }
};
+/**
+ * \brief Faster comparison for string views (compare size before data)
+ *
+ * Still stable, but faster than the normal ordering. */
+static inline int StringViewCompareFast(StringView a, StringView b) {
+ if (a.size() != b.size())
+ return a.size() - b.size();
+
+ return memcmp(a.data(), b.data(), a.size());
+}
+
}