From f378b41f9ab2493bcbc5892d482b18826b0b84c0 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 27 Sep 2016 18:59:11 +0200 Subject: 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). --- apt-pkg/contrib/string_view.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'apt-pkg/contrib') 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()); +} + } -- cgit v1.2.3-70-g09d2