Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: core/src/fxcrt/fx_basic_maps.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: self review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/include/fxcrt/fx_basic.h" 7 #include "core/include/fxcrt/fx_basic.h"
8 #include "plex.h" 8 #include "plex.h"
9 9
10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) 10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 } 54 }
55 } 55 }
56 rNextPosition = (FX_POSITION)pAssocNext; 56 rNextPosition = (FX_POSITION)pAssocNext;
57 rKey = pAssocRet->key; 57 rKey = pAssocRet->key;
58 rValue = pAssocRet->value; 58 rValue = pAssocRet->value;
59 } 59 }
60 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { 60 FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const {
61 FX_DWORD nHash; 61 FX_DWORD nHash;
62 CAssoc* pAssoc = GetAssocAt(key, nHash); 62 CAssoc* pAssoc = GetAssocAt(key, nHash);
63 if (pAssoc == NULL) { 63 if (!pAssoc) {
64 return FALSE; 64 return FALSE;
65 } 65 }
66 rValue = pAssoc->value; 66 rValue = pAssoc->value;
67 return TRUE; 67 return TRUE;
68 } 68 }
69 void* CFX_MapPtrToPtr::GetValueAt(void* key) const { 69 void* CFX_MapPtrToPtr::GetValueAt(void* key) const {
70 FX_DWORD nHash; 70 FX_DWORD nHash;
71 CAssoc* pAssoc = GetAssocAt(key, nHash); 71 CAssoc* pAssoc = GetAssocAt(key, nHash);
72 if (pAssoc == NULL) { 72 if (!pAssoc) {
73 return NULL; 73 return NULL;
74 } 74 }
75 return pAssoc->value; 75 return pAssoc->value;
76 } 76 }
77 void*& CFX_MapPtrToPtr::operator[](void* key) { 77 void*& CFX_MapPtrToPtr::operator[](void* key) {
78 FX_DWORD nHash; 78 FX_DWORD nHash;
79 CAssoc* pAssoc; 79 CAssoc* pAssoc;
80 if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { 80 if ((pAssoc = GetAssocAt(key, nHash)) == NULL) {
81 if (m_pHashTable == NULL) { 81 if (!m_pHashTable) {
82 InitHashTable(m_nHashTableSize); 82 InitHashTable(m_nHashTableSize);
83 } 83 }
84 pAssoc = NewAssoc(); 84 pAssoc = NewAssoc();
85 pAssoc->key = key; 85 pAssoc->key = key;
86 pAssoc->pNext = m_pHashTable[nHash]; 86 pAssoc->pNext = m_pHashTable[nHash];
87 m_pHashTable[nHash] = pAssoc; 87 m_pHashTable[nHash] = pAssoc;
88 } 88 }
89 return pAssoc->value; 89 return pAssoc->value;
90 } 90 }
91 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key, 91 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key,
92 FX_DWORD& nHash) const { 92 FX_DWORD& nHash) const {
93 nHash = HashKey(key) % m_nHashTableSize; 93 nHash = HashKey(key) % m_nHashTableSize;
94 if (m_pHashTable == NULL) { 94 if (!m_pHashTable) {
95 return NULL; 95 return NULL;
96 } 96 }
97 CAssoc* pAssoc; 97 CAssoc* pAssoc;
98 for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) { 98 for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) {
99 if (pAssoc->key == key) { 99 if (pAssoc->key == key) {
100 return pAssoc; 100 return pAssoc;
101 } 101 }
102 } 102 }
103 return NULL; 103 return NULL;
104 } 104 }
105 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() { 105 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() {
106 if (m_pFreeList == NULL) { 106 if (!m_pFreeList) {
107 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, 107 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize,
108 sizeof(CFX_MapPtrToPtr::CAssoc)); 108 sizeof(CFX_MapPtrToPtr::CAssoc));
109 CFX_MapPtrToPtr::CAssoc* pAssoc = 109 CFX_MapPtrToPtr::CAssoc* pAssoc =
110 (CFX_MapPtrToPtr::CAssoc*)newBlock->data(); 110 (CFX_MapPtrToPtr::CAssoc*)newBlock->data();
111 pAssoc += m_nBlockSize - 1; 111 pAssoc += m_nBlockSize - 1;
112 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { 112 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
113 pAssoc->pNext = m_pFreeList; 113 pAssoc->pNext = m_pFreeList;
114 m_pFreeList = pAssoc; 114 m_pFreeList = pAssoc;
115 } 115 }
116 } 116 }
(...skipping 10 matching lines...) Expand all
127 ASSERT(m_nCount == 0); 127 ASSERT(m_nCount == 0);
128 ASSERT(nHashSize > 0); 128 ASSERT(nHashSize > 0);
129 FX_Free(m_pHashTable); 129 FX_Free(m_pHashTable);
130 m_pHashTable = NULL; 130 m_pHashTable = NULL;
131 if (bAllocNow) { 131 if (bAllocNow) {
132 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); 132 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
133 } 133 }
134 m_nHashTableSize = nHashSize; 134 m_nHashTableSize = nHashSize;
135 } 135 }
136 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) { 136 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) {
137 if (m_pHashTable == NULL) { 137 if (!m_pHashTable) {
138 return FALSE; 138 return FALSE;
139 } 139 }
140 CAssoc** ppAssocPrev; 140 CAssoc** ppAssocPrev;
141 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; 141 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize];
142 CAssoc* pAssoc; 142 CAssoc* pAssoc;
143 for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) { 143 for (pAssoc = *ppAssocPrev; pAssoc; pAssoc = pAssoc->pNext) {
144 if (pAssoc->key == key) { 144 if (pAssoc->key == key) {
145 *ppAssocPrev = pAssoc->pNext; 145 *ppAssocPrev = pAssoc->pNext;
146 FreeAssoc(pAssoc); 146 FreeAssoc(pAssoc);
147 return TRUE; 147 return TRUE;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); 232 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
233 if (pKey->m_CompactLen != 0xfe) { 233 if (pKey->m_CompactLen != 0xfe) {
234 return (FX_POSITION)(uintptr_t)(i + 1); 234 return (FX_POSITION)(uintptr_t)(i + 1);
235 } 235 }
236 } 236 }
237 return NULL; 237 return NULL;
238 } 238 }
239 void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, 239 void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
240 CFX_ByteString& rKey, 240 CFX_ByteString& rKey,
241 void*& rValue) const { 241 void*& rValue) const {
242 if (rNextPosition == NULL) { 242 if (!rNextPosition) {
243 return; 243 return;
244 } 244 }
245 int index = (int)(uintptr_t)rNextPosition - 1; 245 int index = (int)(uintptr_t)rNextPosition - 1;
246 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); 246 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
247 rKey = _CompactStringGet(pKey); 247 rKey = _CompactStringGet(pKey);
248 rValue = *(void**)(pKey + 1); 248 rValue = *(void**)(pKey + 1);
249 index++; 249 index++;
250 int size = m_Buffer.GetSize(); 250 int size = m_Buffer.GetSize();
251 while (index < size) { 251 while (index < size) {
252 pKey = (_CompactString*)m_Buffer.GetAt(index); 252 pKey = (_CompactString*)m_Buffer.GetAt(index);
253 if (pKey->m_CompactLen != 0xfe) { 253 if (pKey->m_CompactLen != 0xfe) {
254 rNextPosition = (FX_POSITION)(uintptr_t)(index + 1); 254 rNextPosition = (FX_POSITION)(uintptr_t)(index + 1);
255 return; 255 return;
256 } 256 }
257 index++; 257 index++;
258 } 258 }
259 rNextPosition = NULL; 259 rNextPosition = NULL;
260 } 260 }
261 void* CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const { 261 void* CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const {
262 if (rNextPosition == NULL) { 262 if (!rNextPosition) {
263 return NULL; 263 return NULL;
264 } 264 }
265 int index = (int)(uintptr_t)rNextPosition - 1; 265 int index = (int)(uintptr_t)rNextPosition - 1;
266 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); 266 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
267 void* rValue = *(void**)(pKey + 1); 267 void* rValue = *(void**)(pKey + 1);
268 index++; 268 index++;
269 int size = m_Buffer.GetSize(); 269 int size = m_Buffer.GetSize();
270 while (index < size) { 270 while (index < size) {
271 pKey = (_CompactString*)m_Buffer.GetAt(index); 271 pKey = (_CompactString*)m_Buffer.GetAt(index);
272 if (pKey->m_CompactLen != 0xfe) { 272 if (pKey->m_CompactLen != 0xfe) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 int count = 0; 341 int count = 0;
342 int size = m_Buffer.GetSize(); 342 int size = m_Buffer.GetSize();
343 for (int i = 0; i < size; i++) { 343 for (int i = 0; i < size; i++) {
344 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); 344 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
345 if (pKey->m_CompactLen != 0xfe) { 345 if (pKey->m_CompactLen != 0xfe) {
346 count++; 346 count++;
347 } 347 }
348 } 348 }
349 return count; 349 return count;
350 } 350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698