From 8761fc34f4dedee89f8cd61be8d08845d09f211e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 30 Mar 2015 19:59:08 +0100 Subject: [PATCH] Always go through StringView to compare strings That avoids creating temporary String needlessly --- src/string.hh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/string.hh b/src/string.hh index b1e51e7e3..5e90e98d8 100644 --- a/src/string.hh +++ b/src/string.hh @@ -20,23 +20,6 @@ class StringOps public: using value_type = CharType; - [[gnu::always_inline]] - friend bool operator==(const Type& lhs, const Type& rhs) - { - return lhs.length() == rhs.length() and - std::equal(lhs.begin(), lhs.end(), rhs.begin()); - } - - [[gnu::always_inline]] - friend bool operator!=(const Type& lhs, const Type& rhs) - { return not (lhs == rhs); } - - friend bool operator<(const Type& lhs, const Type& rhs) - { - return std::lexicographical_compare(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()); - } - friend inline size_t hash_value(const Type& str) { return hash_data(str.data(), (int)str.length()); @@ -220,6 +203,23 @@ inline String operator+(StringView lhs, StringView rhs) return res; } +[[gnu::always_inline]] +inline bool operator==(const StringView& lhs, const StringView& rhs) +{ + return lhs.length() == rhs.length() and + std::equal(lhs.begin(), lhs.end(), rhs.begin()); +} + +[[gnu::always_inline]] +inline bool operator!=(const StringView& lhs, const StringView& rhs) +{ return not (lhs == rhs); } + +inline bool operator<(const StringView& lhs, const StringView& rhs) +{ + return std::lexicographical_compare(lhs.begin(), lhs.end(), + rhs.begin(), rhs.end()); +} + Vector split(StringView str, char separator, char escape); Vector split(StringView str, char separator);