summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bytestring.cpp
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-08-15 10:37:59 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-15 15:03:10 +0000
commit8a1758bf11c2d741e0cddc761b1dd2cdf564db93 (patch)
tree82cbafc46f574a05ae0c1d1d3d7f9ebde6cb932d /core/fxcrt/cfx_bytestring.cpp
parent171cb27a720036c48ae3a6176084e880742af0a9 (diff)
downloadpdfium-8a1758bf11c2d741e0cddc761b1dd2cdf564db93.tar.xz
Remove GetAt from string classes
This method duplicates the behaviour of the const [] operator and doesn't offer any additional safety. Folding them into one implementation. SetAt is retained, since implementing the non-const [] operator to replace SetAt has potential performance concerns. Specifically many non-obvious cases of reading an element using [] will cause a realloc & copy. BUG=pdfium:860 Change-Id: I3ef5e5e5a15376f040256b646eb0d90636e24b67 Reviewed-on: https://pdfium-review.googlesource.com/10870 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_bytestring.cpp')
-rw-r--r--core/fxcrt/cfx_bytestring.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/core/fxcrt/cfx_bytestring.cpp b/core/fxcrt/cfx_bytestring.cpp
index 0aba3be12a..cd049dcc5d 100644
--- a/core/fxcrt/cfx_bytestring.cpp
+++ b/core/fxcrt/cfx_bytestring.cpp
@@ -518,6 +518,12 @@ void CFX_ByteString::Format(const char* pFormat, ...) {
va_end(argList);
}
+void CFX_ByteString::SetAt(FX_STRSIZE index, char c) {
+ ASSERT(index >= 0 && index < GetLength());
+ ReallocBeforeWrite(m_pData->m_nDataLength);
+ m_pData->m_String[index] = c;
+}
+
FX_STRSIZE CFX_ByteString::Insert(FX_STRSIZE index, char ch) {
const FX_STRSIZE cur_length = m_pData ? m_pData->m_nDataLength : 0;
if (index != pdfium::clamp(index, 0, cur_length))
@@ -694,12 +700,6 @@ FX_STRSIZE CFX_ByteString::Replace(const CFX_ByteStringC& pOld,
return nCount;
}
-void CFX_ByteString::SetAt(FX_STRSIZE index, char c) {
- ASSERT(index >= 0 && index < GetLength());
- ReallocBeforeWrite(m_pData->m_nDataLength);
- m_pData->m_String[index] = c;
-}
-
CFX_WideString CFX_ByteString::UTF8Decode() const {
CFX_UTF8Decoder decoder;
for (FX_STRSIZE i = 0; i < GetLength(); i++) {
@@ -721,10 +721,10 @@ int CFX_ByteString::Compare(const CFX_ByteStringC& str) const {
int that_len = str.GetLength();
int min_len = this_len < that_len ? this_len : that_len;
for (int i = 0; i < min_len; i++) {
- if ((uint8_t)m_pData->m_String[i] < str.GetAt(i)) {
+ if ((uint8_t)m_pData->m_String[i] < str[i]) {
return -1;
}
- if ((uint8_t)m_pData->m_String[i] > str.GetAt(i)) {
+ if ((uint8_t)m_pData->m_String[i] > str[i]) {
return 1;
}
}