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

Unified Diff: core/fxcrt/fx_basic_wstring.cpp

Issue 1877993002: Make CFX_{Byte,Wide}String::Remove() no-touch if possible (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Extra blank line. 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 | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_wstring.cpp
diff --git a/core/fxcrt/fx_basic_wstring.cpp b/core/fxcrt/fx_basic_wstring.cpp
index 08a9d212d4b79dd2ab49f9a6870574be3d5cab45..069b9fa42d43ac1c5b506682ddc439ab406e76cf 100644
--- a/core/fxcrt/fx_basic_wstring.cpp
+++ b/core/fxcrt/fx_basic_wstring.cpp
@@ -672,17 +672,30 @@ FX_STRSIZE CFX_WideString::Remove(FX_WCHAR chRemove) {
if (!m_pData || m_pData->m_nDataLength < 1)
return 0;
- ReallocBeforeWrite(m_pData->m_nDataLength);
FX_WCHAR* pstrSource = m_pData->m_String;
- FX_WCHAR* pstrDest = m_pData->m_String;
FX_WCHAR* pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
while (pstrSource < pstrEnd) {
+ if (*pstrSource == chRemove)
+ break;
+ pstrSource++;
+ }
+ if (pstrSource == pstrEnd)
+ return 0;
+
+ ptrdiff_t copied = pstrSource - m_pData->m_String;
+ ReallocBeforeWrite(m_pData->m_nDataLength);
+ pstrSource = m_pData->m_String + copied;
+ pstrEnd = m_pData->m_String + m_pData->m_nDataLength;
+
+ FX_WCHAR* pstrDest = pstrSource;
+ while (pstrSource < pstrEnd) {
if (*pstrSource != chRemove) {
*pstrDest = *pstrSource;
pstrDest++;
}
pstrSource++;
}
+
*pstrDest = 0;
FX_STRSIZE nCount = (FX_STRSIZE)(pstrSource - pstrDest);
m_pData->m_nDataLength -= nCount;
« no previous file with comments | « core/fxcrt/fx_basic_bstring_unittest.cpp ('k') | core/fxcrt/fx_basic_wstring_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698