summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-20 12:36:54 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-20 12:36:54 -0800
commit49e4932735292790c77b5362603d9f5d7f6adaaa (patch)
tree51c7c2d0959a5a67aa53e53b4a17adaaeb1c59d6
parent04f01ef650f0abe9b6b18196589ccbaaa623daa3 (diff)
downloadpdfium-49e4932735292790c77b5362603d9f5d7f6adaaa.tar.xz
Merge to XFA: Remove CFX_CMapByteStringToPtr
Original Review URL: https://codereview.chromium.org/1580493002 . (cherry picked from commit 2a312f90dbf5da8b930dee814db786965792961a) TBR=ochang@chromium.org Review URL: https://codereview.chromium.org/1611683002 .
-rw-r--r--core/include/fxcrt/fx_basic.h29
-rw-r--r--core/src/fxcrt/fx_basic_maps.cpp196
2 files changed, 0 insertions, 225 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 4e7c8c84b4..3414dbc13b 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -742,35 +742,6 @@ class CFX_MapPtrTemplate : public CFX_MapPtrToPtr {
}
};
#endif // PDF_ENABLE_XFA
-class CFX_CMapByteStringToPtr {
- public:
- CFX_CMapByteStringToPtr();
-
- ~CFX_CMapByteStringToPtr();
-
- void RemoveAll();
-
- FX_POSITION GetStartPosition() const;
-
- void GetNextAssoc(FX_POSITION& rNextPosition,
- CFX_ByteString& rKey,
- void*& rValue) const;
-
- void* GetNextValue(FX_POSITION& rNextPosition) const;
-
- FX_BOOL Lookup(const CFX_ByteStringC& key, void*& rValue) const;
-
- void SetAt(const CFX_ByteStringC& key, void* value);
-
- void RemoveKey(const CFX_ByteStringC& key);
-
- int GetCount() const;
-
- void AddValue(const CFX_ByteStringC& key, void* pValue);
-
- private:
- CFX_BaseSegmentedArray m_Buffer;
-};
class CFX_PtrList {
protected:
struct CNode {
diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp
index f7d127f7da..d9b634e649 100644
--- a/core/src/fxcrt/fx_basic_maps.cpp
+++ b/core/src/fxcrt/fx_basic_maps.cpp
@@ -7,13 +7,6 @@
#include "core/include/fxcrt/fx_basic.h"
#include "plex.h"
-namespace {
-
-const uint8_t kFreeLength = 0xfe;
-const uint8_t kHasAllocatedBufferLength = 0xff;
-
-} // namespace
-
CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
: m_pHashTable(NULL),
m_nHashTableSize(17),
@@ -164,192 +157,3 @@ void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) {
RemoveAll();
}
}
-struct _CompactString {
- uint8_t m_CompactLen;
- uint8_t m_LenHigh;
- uint8_t m_LenLow;
- uint8_t m_Unused;
- uint8_t* m_pBuffer;
-};
-static void _CompactStringRelease(_CompactString* pCompact) {
- if (pCompact->m_CompactLen == kHasAllocatedBufferLength) {
- FX_Free(pCompact->m_pBuffer);
- }
-}
-static FX_BOOL _CompactStringSame(_CompactString* pCompact,
- const uint8_t* pStr,
- int len) {
- if (len < sizeof(_CompactString)) {
- if (pCompact->m_CompactLen != len) {
- return FALSE;
- }
- return FXSYS_memcmp(&pCompact->m_LenHigh, pStr, len) == 0;
- }
- if (pCompact->m_CompactLen != kHasAllocatedBufferLength ||
- pCompact->m_LenHigh * 256 + pCompact->m_LenLow != len) {
- return FALSE;
- }
- return FXSYS_memcmp(pCompact->m_pBuffer, pStr, len) == 0;
-}
-static void _CompactStringStore(_CompactString* pCompact,
- const uint8_t* pStr,
- int len) {
- if (len < (int)sizeof(_CompactString)) {
- pCompact->m_CompactLen = (uint8_t)len;
- FXSYS_memcpy(&pCompact->m_LenHigh, pStr, len);
- return;
- }
- pCompact->m_CompactLen = kHasAllocatedBufferLength;
- pCompact->m_LenHigh = len / 256;
- pCompact->m_LenLow = len % 256;
- pCompact->m_pBuffer = FX_Alloc(uint8_t, len);
- FXSYS_memcpy(pCompact->m_pBuffer, pStr, len);
-}
-static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) {
- if (pCompact->m_CompactLen == kHasAllocatedBufferLength) {
- return CFX_ByteStringC(pCompact->m_pBuffer,
- pCompact->m_LenHigh * 256 + pCompact->m_LenLow);
- }
- if (pCompact->m_CompactLen == kFreeLength) {
- return CFX_ByteStringC();
- }
- return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen);
-}
-#define CMAP_ALLOC_STEP 8
-#define CMAP_INDEX_SIZE 8
-CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr()
- : m_Buffer(sizeof(_CompactString) + sizeof(void*),
- CMAP_ALLOC_STEP,
- CMAP_INDEX_SIZE) {}
-CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr() {
- RemoveAll();
-}
-void CFX_CMapByteStringToPtr::RemoveAll() {
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i));
- }
- m_Buffer.RemoveAll();
-}
-FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const {
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
- if (pKey->m_CompactLen != kFreeLength) {
- return (FX_POSITION)(uintptr_t)(i + 1);
- }
- }
- return NULL;
-}
-void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
- CFX_ByteString& rKey,
- void*& rValue) const {
- if (!rNextPosition) {
- return;
- }
- int index = (int)(uintptr_t)rNextPosition - 1;
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- rKey = _CompactStringGet(pKey);
- rValue = *(void**)(pKey + 1);
- index++;
- int size = m_Buffer.GetSize();
- while (index < size) {
- pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- rNextPosition = (FX_POSITION)(uintptr_t)(index + 1);
- return;
- }
- index++;
- }
- rNextPosition = NULL;
-}
-void* CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const {
- if (!rNextPosition) {
- return NULL;
- }
- int index = (int)(uintptr_t)rNextPosition - 1;
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- void* rValue = *(void**)(pKey + 1);
- index++;
- int size = m_Buffer.GetSize();
- while (index < size) {
- pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- rNextPosition = (FX_POSITION)(uintptr_t)(index + 1);
- return rValue;
- }
- index++;
- }
- rNextPosition = NULL;
- return rValue;
-}
-FX_BOOL _CMapLookupCallback(void* param, void* pData) {
- return !_CompactStringSame((_CompactString*)pData,
- ((CFX_ByteStringC*)param)->GetPtr(),
- ((CFX_ByteStringC*)param)->GetLength());
-}
-FX_BOOL CFX_CMapByteStringToPtr::Lookup(const CFX_ByteStringC& key,
- void*& rValue) const {
- void* p = m_Buffer.Iterate(_CMapLookupCallback, (void*)&key);
- if (!p) {
- return FALSE;
- }
- rValue = *(void**)((_CompactString*)p + 1);
- return TRUE;
-}
-void CFX_CMapByteStringToPtr::SetAt(const CFX_ByteStringC& key, void* value) {
- ASSERT(value);
- int key_len = key.GetLength();
- int size = m_Buffer.GetSize();
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
- continue;
- }
- *(void**)(pKey + 1) = value;
- return;
- }
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- continue;
- }
- _CompactStringStore(pKey, key.GetPtr(), key_len);
- *(void**)(pKey + 1) = value;
- return;
- }
- _CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, key.GetPtr(), key_len);
- *(void**)(pKey + 1) = value;
-}
-void CFX_CMapByteStringToPtr::AddValue(const CFX_ByteStringC& key,
- void* value) {
- ASSERT(value);
- _CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, key.GetPtr(), key.GetLength());
- *(void**)(pKey + 1) = value;
-}
-void CFX_CMapByteStringToPtr::RemoveKey(const CFX_ByteStringC& key) {
- int key_len = key.GetLength();
- int size = m_Buffer.GetSize();
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
- continue;
- }
- _CompactStringRelease(pKey);
- pKey->m_CompactLen = kFreeLength;
- return;
- }
-}
-int CFX_CMapByteStringToPtr::GetCount() const {
- int count = 0;
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
- if (pKey->m_CompactLen != kFreeLength) {
- count++;
- }
- }
- return count;
-}