diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-08-17 16:26:03 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-08-17 16:26:03 -0700 |
commit | ce4ffb8183af3fa2bb5133f0f7370a88e064c516 (patch) | |
tree | 16f05f79aed56678b45bea435addaa75fbb9f85f /core/src/fxcrt | |
parent | 52a48aadc19b2dee8abeb702269bb168eb6b6999 (diff) | |
download | pdfium-ce4ffb8183af3fa2bb5133f0f7370a88e064c516.tar.xz |
CFX_MapByteStringToPtr considered harmful.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1297723002 .
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r-- | core/src/fxcrt/fx_basic_maps.cpp | 192 |
1 files changed, 0 insertions, 192 deletions
diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp index 1558ae6f75..6bcb91546a 100644 --- a/core/src/fxcrt/fx_basic_maps.cpp +++ b/core/src/fxcrt/fx_basic_maps.cpp @@ -7,12 +7,6 @@ #include "../../include/fxcrt/fx_basic.h" #include "plex.h" -static void ConstructElement(CFX_ByteString* pNewData) { - new (pNewData) CFX_ByteString(); -} -static void DestructElement(CFX_ByteString* pOldData) { - pOldData->~CFX_ByteString(); -} CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) : m_pHashTable(NULL), m_nHashTableSize(17), @@ -165,192 +159,6 @@ void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { RemoveAll(); } } -CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize) - : m_pHashTable(NULL), - m_nHashTableSize(17), - m_nCount(0), - m_pFreeList(NULL), - m_pBlocks(NULL), - m_nBlockSize(nBlockSize) { - ASSERT(m_nBlockSize > 0); -} -void CFX_MapByteStringToPtr::RemoveAll() { - if (m_pHashTable != NULL) { - for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) { - CAssoc* pAssoc; - for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; - pAssoc = pAssoc->pNext) { - DestructElement(&pAssoc->key); - } - } - FX_Free(m_pHashTable); - m_pHashTable = NULL; - } - m_nCount = 0; - m_pFreeList = NULL; - m_pBlocks->FreeDataChain(); - m_pBlocks = NULL; -} -CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr() { - RemoveAll(); - ASSERT(m_nCount == 0); -} -void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, - CFX_ByteString& rKey, - void*& rValue) const { - ASSERT(m_pHashTable != NULL); - CAssoc* pAssocRet = (CAssoc*)rNextPosition; - ASSERT(pAssocRet != NULL); - if (pAssocRet == (CAssoc*)-1) { - for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) - if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { - break; - } - ASSERT(pAssocRet != NULL); - } - CAssoc* pAssocNext; - if ((pAssocNext = pAssocRet->pNext) == NULL) { - for (FX_DWORD nBucket = pAssocRet->nHashValue + 1; - nBucket < m_nHashTableSize; nBucket++) - if ((pAssocNext = m_pHashTable[nBucket]) != NULL) { - break; - } - } - rNextPosition = (FX_POSITION)pAssocNext; - rKey = pAssocRet->key; - rValue = pAssocRet->value; -} -void* CFX_MapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const { - ASSERT(m_pHashTable != NULL); - CAssoc* pAssocRet = (CAssoc*)rNextPosition; - ASSERT(pAssocRet != NULL); - if (pAssocRet == (CAssoc*)-1) { - for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) - if ((pAssocRet = m_pHashTable[nBucket]) != NULL) { - break; - } - ASSERT(pAssocRet != NULL); - } - CAssoc* pAssocNext; - if ((pAssocNext = pAssocRet->pNext) == NULL) { - for (FX_DWORD nBucket = pAssocRet->nHashValue + 1; - nBucket < m_nHashTableSize; nBucket++) - if ((pAssocNext = m_pHashTable[nBucket]) != NULL) { - break; - } - } - rNextPosition = (FX_POSITION)pAssocNext; - return pAssocRet->value; -} -void*& CFX_MapByteStringToPtr::operator[](const CFX_ByteStringC& key) { - FX_DWORD nHash; - CAssoc* pAssoc; - if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { - if (m_pHashTable == NULL) { - InitHashTable(m_nHashTableSize); - } - pAssoc = NewAssoc(); - pAssoc->nHashValue = nHash; - pAssoc->key = key; - pAssoc->pNext = m_pHashTable[nHash]; - m_pHashTable[nHash] = pAssoc; - } - return pAssoc->value; -} -CFX_MapByteStringToPtr::CAssoc* CFX_MapByteStringToPtr::NewAssoc() { - if (m_pFreeList == NULL) { - CFX_Plex* newBlock = CFX_Plex::Create( - m_pBlocks, m_nBlockSize, sizeof(CFX_MapByteStringToPtr::CAssoc)); - CFX_MapByteStringToPtr::CAssoc* pAssoc = - (CFX_MapByteStringToPtr::CAssoc*)newBlock->data(); - pAssoc += m_nBlockSize - 1; - for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { - pAssoc->pNext = m_pFreeList; - m_pFreeList = pAssoc; - } - } - ASSERT(m_pFreeList != NULL); - CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList; - m_pFreeList = m_pFreeList->pNext; - m_nCount++; - ASSERT(m_nCount > 0); - ConstructElement(&pAssoc->key); - pAssoc->value = 0; - return pAssoc; -} -void CFX_MapByteStringToPtr::FreeAssoc(CFX_MapByteStringToPtr::CAssoc* pAssoc) { - DestructElement(&pAssoc->key); - pAssoc->pNext = m_pFreeList; - m_pFreeList = pAssoc; - m_nCount--; - ASSERT(m_nCount >= 0); - if (m_nCount == 0) { - RemoveAll(); - } -} -CFX_MapByteStringToPtr::CAssoc* CFX_MapByteStringToPtr::GetAssocAt( - const CFX_ByteStringC& key, - FX_DWORD& nHash) const { - nHash = HashKey(key) % m_nHashTableSize; - if (m_pHashTable == NULL) { - return NULL; - } - CAssoc* pAssoc; - for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; pAssoc = pAssoc->pNext) { - if (pAssoc->key == key) { - return pAssoc; - } - } - return NULL; -} -FX_BOOL CFX_MapByteStringToPtr::Lookup(const CFX_ByteStringC& key, - void*& rValue) const { - FX_DWORD nHash; - CAssoc* pAssoc = GetAssocAt(key, nHash); - if (pAssoc == NULL) { - return FALSE; - } - rValue = pAssoc->value; - return TRUE; -} -void CFX_MapByteStringToPtr::InitHashTable(FX_DWORD nHashSize, - FX_BOOL bAllocNow) { - ASSERT(m_nCount == 0); - ASSERT(nHashSize > 0); - FX_Free(m_pHashTable); - m_pHashTable = NULL; - if (bAllocNow) { - m_pHashTable = FX_Alloc(CAssoc*, nHashSize); - } - m_nHashTableSize = nHashSize; -} -inline FX_DWORD CFX_MapByteStringToPtr::HashKey( - const CFX_ByteStringC& key) const { - FX_DWORD nHash = 0; - int len = key.GetLength(); - const uint8_t* buf = key.GetPtr(); - for (int i = 0; i < len; i++) { - nHash = (nHash << 5) + nHash + buf[i]; - } - return nHash; -} -FX_BOOL CFX_MapByteStringToPtr::RemoveKey(const CFX_ByteStringC& key) { - if (m_pHashTable == NULL) { - return FALSE; - } - CAssoc** ppAssocPrev; - ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; - CAssoc* pAssoc; - for (pAssoc = *ppAssocPrev; pAssoc != NULL; pAssoc = pAssoc->pNext) { - if (pAssoc->key == key) { - *ppAssocPrev = pAssoc->pNext; - FreeAssoc(pAssoc); - return TRUE; - } - ppAssocPrev = &pAssoc->pNext; - } - return FALSE; -} struct _CompactString { uint8_t m_CompactLen; uint8_t m_LenHigh; |