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 "core/fxcrt/plex.h" | 7 #include "core/fxcrt/plex.h" |
8 #include "core/include/fxcrt/fx_basic.h" | 8 #include "core/include/fxcrt/fx_basic.h" |
9 | 9 |
10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) | 10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) |
(...skipping 21 matching lines...) Expand all Loading... |
32 return ((FX_DWORD)(uintptr_t)key) >> 4; | 32 return ((FX_DWORD)(uintptr_t)key) >> 4; |
33 } | 33 } |
34 void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, | 34 void CFX_MapPtrToPtr::GetNextAssoc(FX_POSITION& rNextPosition, |
35 void*& rKey, | 35 void*& rKey, |
36 void*& rValue) const { | 36 void*& rValue) const { |
37 ASSERT(m_pHashTable); | 37 ASSERT(m_pHashTable); |
38 CAssoc* pAssocRet = (CAssoc*)rNextPosition; | 38 CAssoc* pAssocRet = (CAssoc*)rNextPosition; |
39 ASSERT(pAssocRet); | 39 ASSERT(pAssocRet); |
40 if (pAssocRet == (CAssoc*)-1) { | 40 if (pAssocRet == (CAssoc*)-1) { |
41 for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) { | 41 for (FX_DWORD nBucket = 0; nBucket < m_nHashTableSize; nBucket++) { |
42 if ((pAssocRet = m_pHashTable[nBucket])) | 42 pAssocRet = m_pHashTable[nBucket]; |
| 43 if (pAssocRet) |
43 break; | 44 break; |
44 } | 45 } |
45 ASSERT(pAssocRet); | 46 ASSERT(pAssocRet); |
46 } | 47 } |
47 CAssoc* pAssocNext; | 48 CAssoc* pAssocNext = pAssocRet->pNext; |
48 if ((pAssocNext = pAssocRet->pNext) == NULL) { | 49 for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; |
49 for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; | 50 nBucket < m_nHashTableSize && !pAssocNext; nBucket++) { |
50 nBucket < m_nHashTableSize; nBucket++) { | 51 pAssocNext = m_pHashTable[nBucket]; |
51 if ((pAssocNext = m_pHashTable[nBucket])) { | |
52 break; | |
53 } | |
54 } | |
55 } | 52 } |
56 rNextPosition = (FX_POSITION)pAssocNext; | 53 rNextPosition = (FX_POSITION)pAssocNext; |
57 rKey = pAssocRet->key; | 54 rKey = pAssocRet->key; |
58 rValue = pAssocRet->value; | 55 rValue = pAssocRet->value; |
59 } | 56 } |
60 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { | 57 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { |
61 FX_DWORD nHash; | 58 FX_DWORD nHash; |
62 CAssoc* pAssoc = GetAssocAt(key, nHash); | 59 CAssoc* pAssoc = GetAssocAt(key, nHash); |
63 if (!pAssoc) { | 60 if (!pAssoc) { |
64 return FALSE; | 61 return FALSE; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 } | 147 } |
151 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { | 148 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { |
152 pAssoc->pNext = m_pFreeList; | 149 pAssoc->pNext = m_pFreeList; |
153 m_pFreeList = pAssoc; | 150 m_pFreeList = pAssoc; |
154 m_nCount--; | 151 m_nCount--; |
155 ASSERT(m_nCount >= 0); | 152 ASSERT(m_nCount >= 0); |
156 if (m_nCount == 0) { | 153 if (m_nCount == 0) { |
157 RemoveAll(); | 154 RemoveAll(); |
158 } | 155 } |
159 } | 156 } |
OLD | NEW |