diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-08-19 09:49:24 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-08-19 09:49:24 -0700 |
commit | 09d33bcd82a82cb55039d41651df13e17d6c3e59 (patch) | |
tree | 7a748b7570ff6ad0321c4334319bac101da0e6af /core/src/fxcrt/fx_basic_maps.cpp | |
parent | 1b0023986bc22ce362097b25deb9746b693ef235 (diff) | |
download | pdfium-09d33bcd82a82cb55039d41651df13e17d6c3e59.tar.xz |
Merge to XFA: CFX_MapByteStringToPtr considered harmful (combo patch).
New manual edits: two unused members deleted, one adapted.
fde_csscache.cpp
fde_csscache.h
fpdfxfa_doc.h
fx_ge_fontmap.cpp
(cherry picked from commit 1d9dbd53b205b2b4d9e75a7eeb95e80837917ea3)
(cherry picked from commit cb4d0ea68308e3c51a6ba9551b393bb2f639afc4)
(cherry picked from commit 9cf44c2ed09a8b2ff243eb6dbb72a8cceae1b5ff)
(cherry picked from commit 2a2a6aa7f51352fc481e78f6ad9d41f2738bcc48)
(cherry picked from commit ce4ffb8183af3fa2bb5133f0f7370a88e064c516)
Original Review URL: https://codereview.chromium.org/1297723002 .
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1301793002 .
Diffstat (limited to 'core/src/fxcrt/fx_basic_maps.cpp')
-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; |