summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-12 18:42:18 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-12 18:42:18 +0000
commitf3a7edc07aee2a12cf02ee33471c45b4c6b00307 (patch)
tree1f7158b43c2d9c0ba8bf92a9069adef46e38abc8
parent84435fca8fb06feae5794eb9c8a1ac797708d069 (diff)
downloadpdfium-f3a7edc07aee2a12cf02ee33471c45b4c6b00307.tar.xz
Combine WideString::operator< and Compare().
Change-Id: I3ea13ace6290e8fab41a3f65c9ac047407a74e4d Reviewed-on: https://pdfium-review.googlesource.com/20852 Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fxcrt/widestring.cpp35
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 {