Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: core/fxcrt/fx_basic_bstring.cpp

Issue 1877553002: Avoid copying in TrimRight() and TrimLeft() if possible. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: More accurate comment in fx_string.h Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_bstring_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_bstring.cpp
diff --git a/core/fxcrt/fx_basic_bstring.cpp b/core/fxcrt/fx_basic_bstring.cpp
index 5b9c683c53154b7012ae7f637cb9ed66b154dd30..4a48539578ee5d956d8581e70df766f24a04ffdd 100644
--- a/core/fxcrt/fx_basic_bstring.cpp
+++ b/core/fxcrt/fx_basic_bstring.cpp
@@ -841,7 +841,6 @@ void CFX_ByteString::TrimRight(const CFX_ByteStringC& pTargets) {
if (!m_pData || pTargets.IsEmpty()) {
return;
}
- ReallocBeforeWrite(m_pData->m_nDataLength);
FX_STRSIZE pos = GetLength();
if (pos < 1) {
return;
@@ -858,6 +857,7 @@ void CFX_ByteString::TrimRight(const CFX_ByteStringC& pTargets) {
pos--;
}
if (pos < m_pData->m_nDataLength) {
+ ReallocBeforeWrite(m_pData->m_nDataLength);
m_pData->m_String[pos] = 0;
m_pData->m_nDataLength = pos;
}
@@ -879,7 +879,6 @@ void CFX_ByteString::TrimLeft(const CFX_ByteStringC& pTargets) {
if (len < 1)
return;
- ReallocBeforeWrite(len);
FX_STRSIZE pos = 0;
while (pos < len) {
FX_STRSIZE i = 0;
@@ -892,6 +891,7 @@ void CFX_ByteString::TrimLeft(const CFX_ByteStringC& pTargets) {
pos++;
}
if (pos) {
+ ReallocBeforeWrite(len);
FX_STRSIZE nDataLength = len - pos;
FXSYS_memmove(m_pData->m_String, m_pData->m_String + pos,
(nDataLength + 1) * sizeof(FX_CHAR));
« no previous file with comments | « no previous file | core/fxcrt/fx_basic_bstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698