summaryrefslogtreecommitdiff
path: root/core/fxcrt/bytestring.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-12-20 19:05:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-12-20 19:05:00 +0000
commitcc42afc14b6e54750a95b0e5fd7f01664280c36e (patch)
treefc5d57db9d91bf2ba4581d001d08e7c0f58a725c /core/fxcrt/bytestring.cpp
parent1986bdfb19614b1bf18941b89ded895e237b53ae (diff)
downloadpdfium-cc42afc14b6e54750a95b0e5fd7f01664280c36e.tar.xz
Combine operator< and ByteString::Compare().
Fix or optimize some ByteString::Compare() callers. Change-Id: I0fde91afc3d17fe160b46d00a441ad05e56377e7 Reviewed-on: https://pdfium-review.googlesource.com/20851 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fxcrt/bytestring.cpp')
-rw-r--r--core/fxcrt/bytestring.cpp28
1 files changed, 7 insertions, 21 deletions
diff --git a/core/fxcrt/bytestring.cpp b/core/fxcrt/bytestring.cpp
index 324a2801e4..4c4bd57393 100644
--- a/core/fxcrt/bytestring.cpp
+++ b/core/fxcrt/bytestring.cpp
@@ -317,16 +317,7 @@ bool ByteString::operator<(const char* ptr) const {
}
bool ByteString::operator<(const ByteStringView& str) const {
- if (!m_pData && !str.unterminated_c_str())
- return false;
- if (c_str() == str.unterminated_c_str())
- return false;
-
- size_t len = GetLength();
- size_t other_len = str.GetLength();
- int result =
- memcmp(c_str(), str.unterminated_c_str(), std::min(len, other_len));
- return result < 0 || (result == 0 && len < other_len);
+ return Compare(str) < 0;
}
bool ByteString::operator<(const ByteString& other) const {
@@ -717,17 +708,12 @@ int ByteString::Compare(const ByteStringView& str) const {
size_t this_len = m_pData->m_nDataLength;
size_t that_len = str.GetLength();
size_t min_len = std::min(this_len, that_len);
- for (size_t i = 0; i < min_len; i++) {
- if (static_cast<uint8_t>(m_pData->m_String[i]) < str[i])
- return -1;
- if (static_cast<uint8_t>(m_pData->m_String[i]) > str[i])
- return 1;
- }
- if (this_len < that_len)
- return -1;
- if (this_len > that_len)
- return 1;
- return 0;
+ int result = memcmp(m_pData->m_String, str.unterminated_c_str(), min_len);
+ if (result != 0)
+ return result;
+ if (this_len == that_len)
+ return 0;
+ return this_len < that_len ? -1 : 1;
}
void ByteString::Trim() {