From f6228cae2212a0d7d66c5bbcc364cd23d94ef8d2 Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 3 Aug 2017 12:09:55 +0200 Subject: [PATCH] Utils: Improve SmallString::operator< Change-Id: I893634dd4e95b4103f0fc822e5268cc5f95d3d4b Reviewed-by: Tim Jenssen --- src/libs/utils/smallstring.h | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h index 403155eb66e..aeeeeb98506 100644 --- a/src/libs/utils/smallstring.h +++ b/src/libs/utils/smallstring.h @@ -670,22 +670,14 @@ public: friend bool operator<(const BasicSmallString& first, SmallStringView second) noexcept { - if (first.size() != second.size()) - return first.size() < second.size(); - - const int comparison = std::memcmp(first.data(), second.data(), first.size()); - - return comparison < 0; + return first.size() < second.size() + || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); } friend bool operator<(SmallStringView first, const BasicSmallString& second) noexcept { - if (first.size() != second.size()) - return first.size() < second.size(); - - const int comparison = std::memcmp(first.data(), second.data(), first.size()); - - return comparison < 0; + return first.size() < second.size() + || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); } friend BasicSmallString operator+(const BasicSmallString &first, const BasicSmallString &second) @@ -987,12 +979,8 @@ template class String, || isSameString::value>> bool operator<(const String &first, const String &second) noexcept { - if (first.size() != second.size()) - return first.size() < second.size(); - - const int comparison = std::memcmp(first.data(), second.data(), first.size() + 1); - - return comparison < 0; + return first.size() < second.size() + || (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0); } template