OLD | NEW |
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 "../../include/fxcrt/fx_ext.h" | 7 #include "../../include/fxcrt/fx_ext.h" |
8 #include "plex.h" | 8 #include "plex.h" |
9 static void ConstructElement(CFX_ByteString* pNewData) | 9 static void ConstructElement(CFX_ByteString* pNewData) |
10 { | 10 { |
(...skipping 24 matching lines...) Expand all Loading... |
35 m_pBlocks->FreeDataChain(); | 35 m_pBlocks->FreeDataChain(); |
36 m_pBlocks = NULL; | 36 m_pBlocks = NULL; |
37 } | 37 } |
38 CFX_MapPtrToPtr::~CFX_MapPtrToPtr() | 38 CFX_MapPtrToPtr::~CFX_MapPtrToPtr() |
39 { | 39 { |
40 RemoveAll(); | 40 RemoveAll(); |
41 ASSERT(m_nCount == 0); | 41 ASSERT(m_nCount == 0); |
42 } | 42 } |
43 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const | 43 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const |
44 { | 44 { |
45 return ((FX_DWORD)(FX_UINTPTR)key) >> 4; | 45 return ((FX_DWORD)(uintptr_t)key) >> 4; |
46 } | 46 } |
47 void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void
*& rValue) const | 47 void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, void*& rKey, void
*& rValue) const |
48 { | 48 { |
49 ASSERT(m_pHashTable != NULL); | 49 ASSERT(m_pHashTable != NULL); |
50 CAssoc* pAssocRet = (CAssoc*)rNextPosition; | 50 CAssoc* pAssocRet = (CAssoc*)rNextPosition; |
51 ASSERT(pAssocRet != NULL); | 51 ASSERT(pAssocRet != NULL); |
52 if (pAssocRet == (CAssoc*) - 1) { | 52 if (pAssocRet == (CAssoc*) - 1) { |
53 for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) | 53 for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) |
54 if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { | 54 if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { |
55 break; | 55 break; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 if (pAssoc->key == key) { | 370 if (pAssoc->key == key) { |
371 *ppAssocPrev = pAssoc->pNext; | 371 *ppAssocPrev = pAssoc->pNext; |
372 FreeAssoc(pAssoc); | 372 FreeAssoc(pAssoc); |
373 return TRUE; | 373 return TRUE; |
374 } | 374 } |
375 ppAssocPrev = &pAssoc->pNext; | 375 ppAssocPrev = &pAssoc->pNext; |
376 } | 376 } |
377 return FALSE; | 377 return FALSE; |
378 } | 378 } |
379 struct _CompactString { | 379 struct _CompactString { |
380 FX_BYTE» » m_CompactLen; | 380 uint8_t» » m_CompactLen; |
381 FX_BYTE» » m_LenHigh; | 381 uint8_t» » m_LenHigh; |
382 FX_BYTE» » m_LenLow; | 382 uint8_t» » m_LenLow; |
383 FX_BYTE» » m_Unused; | 383 uint8_t» » m_Unused; |
384 FX_LPBYTE m_pBuffer; | 384 FX_LPBYTE m_pBuffer; |
385 }; | 385 }; |
386 static void _CompactStringRelease(_CompactString* pCompact) | 386 static void _CompactStringRelease(_CompactString* pCompact) |
387 { | 387 { |
388 if (pCompact->m_CompactLen == 0xff) { | 388 if (pCompact->m_CompactLen == 0xff) { |
389 FX_Free(pCompact->m_pBuffer); | 389 FX_Free(pCompact->m_pBuffer); |
390 } | 390 } |
391 } | 391 } |
392 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int
len) | 392 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int
len) |
393 { | 393 { |
394 if (len < sizeof(_CompactString)) { | 394 if (len < sizeof(_CompactString)) { |
395 if (pCompact->m_CompactLen != len) { | 395 if (pCompact->m_CompactLen != len) { |
396 return FALSE; | 396 return FALSE; |
397 } | 397 } |
398 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0; | 398 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0; |
399 } | 399 } |
400 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact->
m_LenLow != len) { | 400 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact->
m_LenLow != len) { |
401 return FALSE; | 401 return FALSE; |
402 } | 402 } |
403 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0; | 403 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0; |
404 } | 404 } |
405 static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int l
en) | 405 static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int l
en) |
406 { | 406 { |
407 if (len < (int)sizeof(_CompactString)) { | 407 if (len < (int)sizeof(_CompactString)) { |
408 pCompact->m_CompactLen = (FX_BYTE)len; | 408 pCompact->m_CompactLen = (uint8_t)len; |
409 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len); | 409 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len); |
410 return; | 410 return; |
411 } | 411 } |
412 pCompact->m_CompactLen = 0xff; | 412 pCompact->m_CompactLen = 0xff; |
413 pCompact->m_LenHigh = len / 256; | 413 pCompact->m_LenHigh = len / 256; |
414 pCompact->m_LenLow = len % 256; | 414 pCompact->m_LenLow = len % 256; |
415 pCompact->m_pBuffer = FX_Alloc(FX_BYTE, len); | 415 pCompact->m_pBuffer = FX_Alloc(uint8_t, len); |
416 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); | 416 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); |
417 } | 417 } |
418 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) | 418 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) |
419 { | 419 { |
420 if (pCompact->m_CompactLen == 0xff) { | 420 if (pCompact->m_CompactLen == 0xff) { |
421 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 +
pCompact->m_LenLow); | 421 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 +
pCompact->m_LenLow); |
422 } | 422 } |
423 if (pCompact->m_CompactLen == 0xfe) { | 423 if (pCompact->m_CompactLen == 0xfe) { |
424 return CFX_ByteStringC(); | 424 return CFX_ByteStringC(); |
425 } | 425 } |
(...skipping 16 matching lines...) Expand all Loading... |
442 _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i)); | 442 _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i)); |
443 } | 443 } |
444 m_Buffer.RemoveAll(); | 444 m_Buffer.RemoveAll(); |
445 } | 445 } |
446 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const | 446 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const |
447 { | 447 { |
448 int size = m_Buffer.GetSize(); | 448 int size = m_Buffer.GetSize(); |
449 for (int i = 0; i < size; i ++) { | 449 for (int i = 0; i < size; i ++) { |
450 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); | 450 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); |
451 if (pKey->m_CompactLen != 0xfe) { | 451 if (pKey->m_CompactLen != 0xfe) { |
452 return (FX_POSITION)(FX_UINTPTR)(i + 1); | 452 return (FX_POSITION)(uintptr_t)(i + 1); |
453 } | 453 } |
454 } | 454 } |
455 return NULL; | 455 return NULL; |
456 } | 456 } |
457 void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteS
tring& rKey, void*& rValue) const | 457 void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, CFX_ByteS
tring& rKey, void*& rValue) const |
458 { | 458 { |
459 if (rNextPosition == NULL) { | 459 if (rNextPosition == NULL) { |
460 return; | 460 return; |
461 } | 461 } |
462 int index = (int)(FX_UINTPTR)rNextPosition - 1; | 462 int index = (int)(uintptr_t)rNextPosition - 1; |
463 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); | 463 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); |
464 rKey = _CompactStringGet(pKey); | 464 rKey = _CompactStringGet(pKey); |
465 rValue = *(void**)(pKey + 1); | 465 rValue = *(void**)(pKey + 1); |
466 index ++; | 466 index ++; |
467 int size = m_Buffer.GetSize(); | 467 int size = m_Buffer.GetSize(); |
468 while (index < size) { | 468 while (index < size) { |
469 pKey = (_CompactString*)m_Buffer.GetAt(index); | 469 pKey = (_CompactString*)m_Buffer.GetAt(index); |
470 if (pKey->m_CompactLen != 0xfe) { | 470 if (pKey->m_CompactLen != 0xfe) { |
471 rNextPosition = (FX_POSITION)(FX_UINTPTR)(index + 1); | 471 rNextPosition = (FX_POSITION)(uintptr_t)(index + 1); |
472 return; | 472 return; |
473 } | 473 } |
474 index ++; | 474 index ++; |
475 } | 475 } |
476 rNextPosition = NULL; | 476 rNextPosition = NULL; |
477 } | 477 } |
478 FX_LPVOID CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) cons
t | 478 FX_LPVOID CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) cons
t |
479 { | 479 { |
480 if (rNextPosition == NULL) { | 480 if (rNextPosition == NULL) { |
481 return NULL; | 481 return NULL; |
482 } | 482 } |
483 int index = (int)(FX_UINTPTR)rNextPosition - 1; | 483 int index = (int)(uintptr_t)rNextPosition - 1; |
484 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); | 484 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); |
485 FX_LPVOID rValue = *(void**)(pKey + 1); | 485 FX_LPVOID rValue = *(void**)(pKey + 1); |
486 index ++; | 486 index ++; |
487 int size = m_Buffer.GetSize(); | 487 int size = m_Buffer.GetSize(); |
488 while (index < size) { | 488 while (index < size) { |
489 pKey = (_CompactString*)m_Buffer.GetAt(index); | 489 pKey = (_CompactString*)m_Buffer.GetAt(index); |
490 if (pKey->m_CompactLen != 0xfe) { | 490 if (pKey->m_CompactLen != 0xfe) { |
491 rNextPosition = (FX_POSITION)(FX_UINTPTR)(index + 1); | 491 rNextPosition = (FX_POSITION)(uintptr_t)(index + 1); |
492 return rValue; | 492 return rValue; |
493 } | 493 } |
494 index ++; | 494 index ++; |
495 } | 495 } |
496 rNextPosition = NULL; | 496 rNextPosition = NULL; |
497 return rValue; | 497 return rValue; |
498 } | 498 } |
499 FX_BOOL _CMapLookupCallback(void* param, void* pData) | 499 FX_BOOL _CMapLookupCallback(void* param, void* pData) |
500 { | 500 { |
501 return !_CompactStringSame((_CompactString*)pData, ((CFX_ByteStringC*)param)
->GetPtr(), ((CFX_ByteStringC*)param)->GetLength()); | 501 return !_CompactStringSame((_CompactString*)pData, ((CFX_ByteStringC*)param)
->GetPtr(), ((CFX_ByteStringC*)param)->GetLength()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 if (count == 0) { | 594 if (count == 0) { |
595 return NULL; | 595 return NULL; |
596 } | 596 } |
597 return (FX_POSITION)1; | 597 return (FX_POSITION)1; |
598 } | 598 } |
599 void CFX_CMapDWordToDWord::GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWOR
D& value) const | 599 void CFX_CMapDWordToDWord::GetNextAssoc(FX_POSITION& pos, FX_DWORD& key, FX_DWOR
D& value) const |
600 { | 600 { |
601 if (pos == 0) { | 601 if (pos == 0) { |
602 return; | 602 return; |
603 } | 603 } |
604 FX_DWORD index = ((FX_DWORD)(FX_UINTPTR)pos) - 1; | 604 FX_DWORD index = ((FX_DWORD)(uintptr_t)pos) - 1; |
605 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); | 605 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); |
606 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); | 606 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); |
607 key = buf[index].key; | 607 key = buf[index].key; |
608 value = buf[index].value; | 608 value = buf[index].value; |
609 if (index == count - 1) { | 609 if (index == count - 1) { |
610 pos = 0; | 610 pos = 0; |
611 } else { | 611 } else { |
612 pos = (FX_POSITION)((FX_UINTPTR)pos + 1); | 612 pos = (FX_POSITION)((uintptr_t)pos + 1); |
613 } | 613 } |
614 } | 614 } |
615 void CFX_CMapDWordToDWord::SetAt(FX_DWORD key, FX_DWORD value) | 615 void CFX_CMapDWordToDWord::SetAt(FX_DWORD key, FX_DWORD value) |
616 { | 616 { |
617 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); | 617 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); |
618 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); | 618 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); |
619 _DWordPair pair = {key, value}; | 619 _DWordPair pair = {key, value}; |
620 if (count == 0 || key > buf[count - 1].key) { | 620 if (count == 0 || key > buf[count - 1].key) { |
621 m_Buffer.AppendBlock(&pair, sizeof(_DWordPair)); | 621 m_Buffer.AppendBlock(&pair, sizeof(_DWordPair)); |
622 return; | 622 return; |
623 } | 623 } |
624 int low = 0, high = count - 1; | 624 int low = 0, high = count - 1; |
625 while (low <= high) { | 625 while (low <= high) { |
626 int mid = (low + high) / 2; | 626 int mid = (low + high) / 2; |
627 if (buf[mid].key < key) { | 627 if (buf[mid].key < key) { |
628 low = mid + 1; | 628 low = mid + 1; |
629 } else if (buf[mid].key > key) { | 629 } else if (buf[mid].key > key) { |
630 high = mid - 1; | 630 high = mid - 1; |
631 } else { | 631 } else { |
632 buf[mid].value = value; | 632 buf[mid].value = value; |
633 return; | 633 return; |
634 } | 634 } |
635 } | 635 } |
636 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); | 636 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); |
637 } | 637 } |
638 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) | 638 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) |
639 { | 639 { |
640 m_Buffer.EstimateSize(size, grow_by); | 640 m_Buffer.EstimateSize(size, grow_by); |
641 } | 641 } |
OLD | NEW |