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

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

Issue 1919563002: Pass CFX_*StringCs to FX_HashCode_GETA and _GETW hash functions. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix issue from c4 Created 4 years, 7 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 | « no previous file | core/fxcrt/fx_extension_unittest.cpp » ('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 "core/fxcrt/extension.h" 7 #include "core/fxcrt/extension.h"
8 #include "core/fxcrt/include/fx_basic.h" 8 #include "core/fxcrt/include/fx_basic.h"
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 10
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 FX_CHAR ch1 = 0, ch2 = 0; 210 FX_CHAR ch1 = 0, ch2 = 0;
211 while (count-- > 0) { 211 while (count-- > 0) {
212 ch1 = (FX_CHAR)FXSYS_tolower(*s1++); 212 ch1 = (FX_CHAR)FXSYS_tolower(*s1++);
213 ch2 = (FX_CHAR)FXSYS_tolower(*s2++); 213 ch2 = (FX_CHAR)FXSYS_tolower(*s2++);
214 if (ch1 != ch2) { 214 if (ch1 != ch2) {
215 break; 215 break;
216 } 216 }
217 } 217 }
218 return ch1 - ch2; 218 return ch1 - ch2;
219 } 219 }
220 uint32_t FX_HashCode_String_GetA(const FX_CHAR* pStr, 220
221 int32_t iLength, 221 uint32_t FX_HashCode_GetA(const CFX_ByteStringC& str, bool bIgnoreCase) {
222 FX_BOOL bIgnoreCase) { 222 const FX_CHAR* pStr = str.c_str();
223 FXSYS_assert(pStr); 223 const FX_CHAR* pStrEnd = pStr + str.GetLength();
224 if (iLength < 0) {
225 iLength = (int32_t)FXSYS_strlen(pStr);
226 }
227 const FX_CHAR* pStrEnd = pStr + iLength;
228 uint32_t dwHashCode = 0; 224 uint32_t dwHashCode = 0;
229 if (bIgnoreCase) { 225 if (bIgnoreCase) {
230 while (pStr < pStrEnd) { 226 while (pStr < pStrEnd) {
231 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++); 227 dwHashCode = 31 * dwHashCode + FXSYS_tolower(*pStr++);
232 } 228 }
233 } else { 229 } else {
234 while (pStr < pStrEnd) { 230 while (pStr < pStrEnd) {
235 dwHashCode = 31 * dwHashCode + *pStr++; 231 dwHashCode = 31 * dwHashCode + *pStr++;
236 } 232 }
237 } 233 }
238 return dwHashCode; 234 return dwHashCode;
239 } 235 }
240 uint32_t FX_HashCode_String_GetW(const FX_WCHAR* pStr, 236
241 int32_t iLength, 237 uint32_t FX_HashCode_GetW(const CFX_WideStringC& str, bool bIgnoreCase) {
242 FX_BOOL bIgnoreCase) { 238 const FX_WCHAR* pStr = str.c_str();
243 FXSYS_assert(pStr); 239 const FX_WCHAR* pStrEnd = pStr + str.GetLength();
244 if (iLength < 0) {
245 iLength = (int32_t)FXSYS_wcslen(pStr);
246 }
247 const FX_WCHAR* pStrEnd = pStr + iLength;
248 uint32_t dwHashCode = 0; 240 uint32_t dwHashCode = 0;
249 if (bIgnoreCase) { 241 if (bIgnoreCase) {
250 while (pStr < pStrEnd) { 242 while (pStr < pStrEnd) {
251 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++); 243 dwHashCode = 1313 * dwHashCode + FXSYS_tolower(*pStr++);
252 } 244 }
253 } else { 245 } else {
254 while (pStr < pStrEnd) { 246 while (pStr < pStrEnd) {
255 dwHashCode = 1313 * dwHashCode + *pStr++; 247 dwHashCode = 1313 * dwHashCode + *pStr++;
256 } 248 }
257 } 249 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 FX_Random_MT_Close(pContext); 312 FX_Random_MT_Close(pContext);
321 } 313 }
322 void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount) { 314 void FX_Random_GenerateBase(uint32_t* pBuffer, int32_t iCount) {
323 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 315 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
324 SYSTEMTIME st1, st2; 316 SYSTEMTIME st1, st2;
325 ::GetSystemTime(&st1); 317 ::GetSystemTime(&st1);
326 do { 318 do {
327 ::GetSystemTime(&st2); 319 ::GetSystemTime(&st2);
328 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0); 320 } while (FXSYS_memcmp(&st1, &st2, sizeof(SYSTEMTIME)) == 0);
329 uint32_t dwHash1 = 321 uint32_t dwHash1 =
330 FX_HashCode_String_GetA((const FX_CHAR*)&st1, sizeof(st1), TRUE); 322 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st1, sizeof(st1)), true);
331 uint32_t dwHash2 = 323 uint32_t dwHash2 =
332 FX_HashCode_String_GetA((const FX_CHAR*)&st2, sizeof(st2), TRUE); 324 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)&st2, sizeof(st2)), true);
333 ::srand((dwHash1 << 16) | (uint32_t)dwHash2); 325 ::srand((dwHash1 << 16) | (uint32_t)dwHash2);
334 #else 326 #else
335 time_t tmLast = time(NULL); 327 time_t tmLast = time(NULL);
336 time_t tmCur; 328 time_t tmCur;
337 while ((tmCur = time(NULL)) == tmLast) { 329 while ((tmCur = time(NULL)) == tmLast) {
338 continue; 330 continue;
339 } 331 }
340 332
341 ::srand((tmCur << 16) | (tmLast & 0xFFFF)); 333 ::srand((tmCur << 16) | (tmLast & 0xFFFF));
342 #endif 334 #endif
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 b = ((const uint8_t*)pGUID)[i]; 371 b = ((const uint8_t*)pGUID)[i];
380 *pBuf++ = gs_FX_pHexChars[b >> 4]; 372 *pBuf++ = gs_FX_pHexChars[b >> 4];
381 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 373 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
382 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 374 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
383 *pBuf++ = L'-'; 375 *pBuf++ = L'-';
384 } 376 }
385 } 377 }
386 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 378 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
387 } 379 }
388 #endif // PDF_ENABLE_XFA 380 #endif // PDF_ENABLE_XFA
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/fx_extension_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698