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

Side by Side Diff: core/fxcrt/fx_basic_wstring.cpp

Issue 2347433004: Add short-cut in CFX_{Byte,Wide}String::Operator<() (Closed)
Patch Set: Logic goof Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/include/fx_string.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return other.IsEmpty(); 187 return other.IsEmpty();
188 188
189 if (other.IsEmpty()) 189 if (other.IsEmpty())
190 return false; 190 return false;
191 191
192 return other.m_pData->m_nDataLength == m_pData->m_nDataLength && 192 return other.m_pData->m_nDataLength == m_pData->m_nDataLength &&
193 wmemcmp(other.m_pData->m_String, m_pData->m_String, 193 wmemcmp(other.m_pData->m_String, m_pData->m_String,
194 m_pData->m_nDataLength) == 0; 194 m_pData->m_nDataLength) == 0;
195 } 195 }
196 196
197 bool CFX_WideString::operator<(const CFX_WideString& str) const {
198 if (m_pData == str.m_pData)
199 return false;
200
201 int result =
202 wmemcmp(c_str(), str.c_str(), std::min(GetLength(), str.GetLength()));
203 return result < 0 || (result == 0 && GetLength() < str.GetLength());
204 }
205
197 void CFX_WideString::AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen) { 206 void CFX_WideString::AssignCopy(const FX_WCHAR* pSrcData, FX_STRSIZE nSrcLen) {
198 AllocBeforeWrite(nSrcLen); 207 AllocBeforeWrite(nSrcLen);
199 m_pData->CopyContents(pSrcData, nSrcLen); 208 m_pData->CopyContents(pSrcData, nSrcLen);
200 m_pData->m_nDataLength = nSrcLen; 209 m_pData->m_nDataLength = nSrcLen;
201 } 210 }
202 211
203 void CFX_WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) { 212 void CFX_WideString::ReallocBeforeWrite(FX_STRSIZE nNewLength) {
204 if (m_pData && m_pData->CanOperateInPlace(nNewLength)) 213 if (m_pData && m_pData->CanOperateInPlace(nNewLength))
205 return; 214 return;
206 215
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0); 1012 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, nullptr, 0);
1004 CFX_WideString wstr; 1013 CFX_WideString wstr;
1005 if (dest_len) { 1014 if (dest_len) {
1006 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len); 1015 FX_WCHAR* dest_buf = wstr.GetBuffer(dest_len);
1007 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf, 1016 FXSYS_MultiByteToWideChar(codepage, 0, bstr.c_str(), src_len, dest_buf,
1008 dest_len); 1017 dest_len);
1009 wstr.ReleaseBuffer(dest_len); 1018 wstr.ReleaseBuffer(dest_len);
1010 } 1019 }
1011 return wstr; 1020 return wstr;
1012 } 1021 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_bstring.cpp ('k') | core/fxcrt/include/fx_string.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698