| 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_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
| 8 #include "plex.h" | 8 #include "plex.h" |
| 9 | 9 |
| 10 static void ConstructElement(CFX_ByteString* pNewData) { | 10 static void ConstructElement(CFX_ByteString* pNewData) { |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 int count = 0; | 533 int count = 0; |
| 534 int size = m_Buffer.GetSize(); | 534 int size = m_Buffer.GetSize(); |
| 535 for (int i = 0; i < size; i++) { | 535 for (int i = 0; i < size; i++) { |
| 536 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); | 536 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); |
| 537 if (pKey->m_CompactLen != 0xfe) { | 537 if (pKey->m_CompactLen != 0xfe) { |
| 538 count++; | 538 count++; |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 return count; | 541 return count; |
| 542 } | 542 } |
| 543 extern "C" { | |
| 544 static int _CompareDWord(const void* p1, const void* p2) { | |
| 545 return (*(FX_DWORD*)p1) - (*(FX_DWORD*)p2); | |
| 546 } | |
| 547 }; | |
| 548 struct _DWordPair { | |
| 549 FX_DWORD key; | |
| 550 FX_DWORD value; | |
| 551 }; | |
| 552 FX_BOOL CFX_CMapDWordToDWord::Lookup(FX_DWORD key, FX_DWORD& value) const { | |
| 553 void* pResult = FXSYS_bsearch(&key, m_Buffer.GetBuffer(), | |
| 554 m_Buffer.GetSize() / sizeof(_DWordPair), | |
| 555 sizeof(_DWordPair), _CompareDWord); | |
| 556 if (pResult == NULL) { | |
| 557 return FALSE; | |
| 558 } | |
| 559 value = ((FX_DWORD*)pResult)[1]; | |
| 560 return TRUE; | |
| 561 } | |
| 562 FX_POSITION CFX_CMapDWordToDWord::GetStartPosition() const { | |
| 563 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); | |
| 564 if (count == 0) { | |
| 565 return NULL; | |
| 566 } | |
| 567 return (FX_POSITION)1; | |
| 568 } | |
| 569 void CFX_CMapDWordToDWord::GetNextAssoc(FX_POSITION& pos, | |
| 570 FX_DWORD& key, | |
| 571 FX_DWORD& value) const { | |
| 572 if (pos == 0) { | |
| 573 return; | |
| 574 } | |
| 575 FX_DWORD index = ((FX_DWORD)(uintptr_t)pos) - 1; | |
| 576 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); | |
| 577 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); | |
| 578 key = buf[index].key; | |
| 579 value = buf[index].value; | |
| 580 if (index == count - 1) { | |
| 581 pos = 0; | |
| 582 } else { | |
| 583 pos = (FX_POSITION)((uintptr_t)pos + 1); | |
| 584 } | |
| 585 } | |
| 586 void CFX_CMapDWordToDWord::SetAt(FX_DWORD key, FX_DWORD value) { | |
| 587 FX_DWORD count = m_Buffer.GetSize() / sizeof(_DWordPair); | |
| 588 _DWordPair* buf = (_DWordPair*)m_Buffer.GetBuffer(); | |
| 589 _DWordPair pair = {key, value}; | |
| 590 if (count == 0 || key > buf[count - 1].key) { | |
| 591 m_Buffer.AppendBlock(&pair, sizeof(_DWordPair)); | |
| 592 return; | |
| 593 } | |
| 594 int low = 0, high = count - 1; | |
| 595 while (low <= high) { | |
| 596 int mid = (low + high) / 2; | |
| 597 if (buf[mid].key < key) { | |
| 598 low = mid + 1; | |
| 599 } else if (buf[mid].key > key) { | |
| 600 high = mid - 1; | |
| 601 } else { | |
| 602 buf[mid].value = value; | |
| 603 return; | |
| 604 } | |
| 605 } | |
| 606 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); | |
| 607 } | |
| 608 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) { | |
| 609 m_Buffer.EstimateSize(size, grow_by); | |
| 610 } | |
| OLD | NEW |