forked from qt-creator/qt-creator
Utils: Improve SmallString::operator<
Change-Id: I893634dd4e95b4103f0fc822e5268cc5f95d3d4b Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -670,22 +670,14 @@ public:
|
|||||||
|
|
||||||
friend bool operator<(const BasicSmallString& first, SmallStringView second) noexcept
|
friend bool operator<(const BasicSmallString& first, SmallStringView second) noexcept
|
||||||
{
|
{
|
||||||
if (first.size() != second.size())
|
return first.size() < second.size()
|
||||||
return first.size() < second.size();
|
|| (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0);
|
||||||
|
|
||||||
const int comparison = std::memcmp(first.data(), second.data(), first.size());
|
|
||||||
|
|
||||||
return comparison < 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator<(SmallStringView first, const BasicSmallString& second) noexcept
|
friend bool operator<(SmallStringView first, const BasicSmallString& second) noexcept
|
||||||
{
|
{
|
||||||
if (first.size() != second.size())
|
return first.size() < second.size()
|
||||||
return first.size() < second.size();
|
|| (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0);
|
||||||
|
|
||||||
const int comparison = std::memcmp(first.data(), second.data(), first.size());
|
|
||||||
|
|
||||||
return comparison < 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
friend BasicSmallString operator+(const BasicSmallString &first, const BasicSmallString &second)
|
friend BasicSmallString operator+(const BasicSmallString &first, const BasicSmallString &second)
|
||||||
@@ -987,12 +979,8 @@ template<template<uint> class String,
|
|||||||
|| isSameString<String, SizeTwo>::value>>
|
|| isSameString<String, SizeTwo>::value>>
|
||||||
bool operator<(const String<SizeOne> &first, const String<SizeTwo> &second) noexcept
|
bool operator<(const String<SizeOne> &first, const String<SizeTwo> &second) noexcept
|
||||||
{
|
{
|
||||||
if (first.size() != second.size())
|
return first.size() < second.size()
|
||||||
return first.size() < second.size();
|
|| (first.size() == second.size() && std::memcmp(first.data(), second.data(), first.size()) < 0);
|
||||||
|
|
||||||
const int comparison = std::memcmp(first.data(), second.data(), first.size() + 1);
|
|
||||||
|
|
||||||
return comparison < 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Key,
|
template<typename Key,
|
||||||
|
|||||||
Reference in New Issue
Block a user