diff options
Diffstat (limited to 'core/fxcrt/widestring.cpp')
-rw-r--r-- | core/fxcrt/widestring.cpp | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/core/fxcrt/widestring.cpp b/core/fxcrt/widestring.cpp index 2caa3b4213..3b72c8fa94 100644 --- a/core/fxcrt/widestring.cpp +++ b/core/fxcrt/widestring.cpp @@ -500,15 +500,7 @@ bool WideString::operator==(const WideString& other) const { } bool WideString::operator<(const wchar_t* ptr) const { - if (!m_pData && !ptr) - return false; - if (c_str() == ptr) - return false; - - size_t len = GetLength(); - size_t other_len = ptr ? wcslen(ptr) : 0; - int result = wmemcmp(c_str(), ptr, std::min(len, other_len)); - return result < 0 || (result == 0 && len < other_len); + return Compare(ptr) < 0; } bool WideString::operator<(const WideStringView& str) const { @@ -525,13 +517,7 @@ bool WideString::operator<(const WideStringView& str) const { } bool WideString::operator<(const WideString& other) const { - if (m_pData == other.m_pData) - return false; - - size_t len = GetLength(); - size_t other_len = other.GetLength(); - int result = wmemcmp(c_str(), other.c_str(), std::min(len, other_len)); - return result < 0 || (result == 0 && len < other_len); + return Compare(other) < 0; } void WideString::AssignCopy(const wchar_t* pSrcData, size_t nSrcLen) { @@ -933,17 +919,12 @@ int WideString::Compare(const WideString& str) const { size_t this_len = m_pData->m_nDataLength; size_t that_len = str.m_pData->m_nDataLength; size_t min_len = std::min(this_len, that_len); - for (size_t i = 0; i < min_len; i++) { - if (m_pData->m_String[i] < str.m_pData->m_String[i]) - return -1; - if (m_pData->m_String[i] > str.m_pData->m_String[i]) - return 1; - } - if (this_len < that_len) - return -1; - if (this_len > that_len) - return 1; - return 0; + int result = wmemcmp(m_pData->m_String, str.m_pData->m_String, min_len); + if (result != 0) + return result; + if (this_len == that_len) + return 0; + return this_len < that_len; } int WideString::CompareNoCase(const wchar_t* lpsz) const { |