Chromium Code Reviews| 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 if (!pAssocNext) { |
|
Tom Sepez
2016/03/17 16:40:05
Do we still need this if given the check at 51?
Wei Li
2016/03/18 17:42:39
Done.
| |
| 49 for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; | 50 for (FX_DWORD nBucket = (HashKey(pAssocRet->key) % m_nHashTableSize) + 1; |
|
Tom Sepez
2016/03/17 16:40:05
nit: [super nit] Maybe this reads cleaner as
CAss
Wei Li
2016/03/18 17:42:39
I agree with you on the readability for the loop.
| |
| 50 nBucket < m_nHashTableSize; nBucket++) { | 51 nBucket < m_nHashTableSize && !pAssocNext; nBucket++) { |
| 51 if ((pAssocNext = m_pHashTable[nBucket])) { | 52 pAssocNext = m_pHashTable[nBucket]; |
| 52 break; | |
| 53 } | |
| 54 } | 53 } |
| 55 } | 54 } |
| 56 rNextPosition = (FX_POSITION)pAssocNext; | 55 rNextPosition = (FX_POSITION)pAssocNext; |
| 57 rKey = pAssocRet->key; | 56 rKey = pAssocRet->key; |
| 58 rValue = pAssocRet->value; | 57 rValue = pAssocRet->value; |
| 59 } | 58 } |
| 60 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { | 59 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { |
| 61 FX_DWORD nHash; | 60 FX_DWORD nHash; |
| 62 CAssoc* pAssoc = GetAssocAt(key, nHash); | 61 CAssoc* pAssoc = GetAssocAt(key, nHash); |
| 63 if (!pAssoc) { | 62 if (!pAssoc) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 } | 149 } |
| 151 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { | 150 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) { |
| 152 pAssoc->pNext = m_pFreeList; | 151 pAssoc->pNext = m_pFreeList; |
| 153 m_pFreeList = pAssoc; | 152 m_pFreeList = pAssoc; |
| 154 m_nCount--; | 153 m_nCount--; |
| 155 ASSERT(m_nCount >= 0); | 154 ASSERT(m_nCount >= 0); |
| 156 if (m_nCount == 0) { | 155 if (m_nCount == 0) { |
| 157 RemoveAll(); | 156 RemoveAll(); |
| 158 } | 157 } |
| 159 } | 158 } |
| OLD | NEW |