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

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

Issue 2032613003: Get rid of NULLs in core/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix a bad merge Created 4 years, 6 months 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
« no previous file with comments | « core/fxcrt/fx_basic_list.cpp ('k') | core/fxcrt/fx_extension.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/fxcrt/include/fx_basic.h" 7 #include "core/fxcrt/include/fx_basic.h"
8 #include "core/fxcrt/plex.h" 8 #include "core/fxcrt/plex.h"
9 9
10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) 10 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 void* CFX_MapPtrToPtr::GetValueAt(void* key) const { 71 void* CFX_MapPtrToPtr::GetValueAt(void* key) const {
72 uint32_t nHash; 72 uint32_t nHash;
73 CAssoc* pAssoc = GetAssocAt(key, nHash); 73 CAssoc* pAssoc = GetAssocAt(key, nHash);
74 return pAssoc ? pAssoc->value : nullptr; 74 return pAssoc ? pAssoc->value : nullptr;
75 } 75 }
76 76
77 void*& CFX_MapPtrToPtr::operator[](void* key) { 77 void*& CFX_MapPtrToPtr::operator[](void* key) {
78 uint32_t nHash; 78 uint32_t nHash;
79 CAssoc* pAssoc; 79 CAssoc* pAssoc = GetAssocAt(key, nHash);
80 if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { 80 if (!pAssoc) {
81 if (!m_pHashTable) { 81 if (!m_pHashTable)
82 InitHashTable(m_nHashTableSize); 82 InitHashTable(m_nHashTableSize);
83 }
84 pAssoc = NewAssoc(); 83 pAssoc = NewAssoc();
85 pAssoc->key = key; 84 pAssoc->key = key;
86 pAssoc->pNext = m_pHashTable[nHash]; 85 pAssoc->pNext = m_pHashTable[nHash];
87 m_pHashTable[nHash] = pAssoc; 86 m_pHashTable[nHash] = pAssoc;
88 } 87 }
89 return pAssoc->value; 88 return pAssoc->value;
90 } 89 }
91 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key, 90 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::GetAssocAt(void* key,
92 uint32_t& nHash) const { 91 uint32_t& nHash) const {
93 nHash = HashKey(key) % m_nHashTableSize; 92 nHash = HashKey(key) % m_nHashTableSize;
94 if (!m_pHashTable) { 93 if (!m_pHashTable) {
95 return NULL; 94 return nullptr;
96 } 95 }
97 CAssoc* pAssoc; 96 CAssoc* pAssoc;
98 for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) { 97 for (pAssoc = m_pHashTable[nHash]; pAssoc; pAssoc = pAssoc->pNext) {
99 if (pAssoc->key == key) 98 if (pAssoc->key == key)
100 return pAssoc; 99 return pAssoc;
101 } 100 }
102 return NULL; 101 return nullptr;
103 } 102 }
104 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() { 103 CFX_MapPtrToPtr::CAssoc* CFX_MapPtrToPtr::NewAssoc() {
105 if (!m_pFreeList) { 104 if (!m_pFreeList) {
106 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, 105 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize,
107 sizeof(CFX_MapPtrToPtr::CAssoc)); 106 sizeof(CFX_MapPtrToPtr::CAssoc));
108 CFX_MapPtrToPtr::CAssoc* pAssoc = 107 CFX_MapPtrToPtr::CAssoc* pAssoc =
109 (CFX_MapPtrToPtr::CAssoc*)newBlock->data(); 108 (CFX_MapPtrToPtr::CAssoc*)newBlock->data();
110 pAssoc += m_nBlockSize - 1; 109 pAssoc += m_nBlockSize - 1;
111 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { 110 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
112 pAssoc->pNext = m_pFreeList; 111 pAssoc->pNext = m_pFreeList;
113 m_pFreeList = pAssoc; 112 m_pFreeList = pAssoc;
114 } 113 }
115 } 114 }
116 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList; 115 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList;
117 m_pFreeList = m_pFreeList->pNext; 116 m_pFreeList = m_pFreeList->pNext;
118 m_nCount++; 117 m_nCount++;
119 ASSERT(m_nCount > 0); 118 ASSERT(m_nCount > 0);
120 pAssoc->key = 0; 119 pAssoc->key = 0;
121 pAssoc->value = 0; 120 pAssoc->value = 0;
122 return pAssoc; 121 return pAssoc;
123 } 122 }
124 void CFX_MapPtrToPtr::InitHashTable(uint32_t nHashSize, FX_BOOL bAllocNow) { 123 void CFX_MapPtrToPtr::InitHashTable(uint32_t nHashSize, FX_BOOL bAllocNow) {
125 ASSERT(m_nCount == 0); 124 ASSERT(m_nCount == 0);
126 ASSERT(nHashSize > 0); 125 ASSERT(nHashSize > 0);
127 FX_Free(m_pHashTable); 126 FX_Free(m_pHashTable);
128 m_pHashTable = NULL; 127 m_pHashTable = nullptr;
129 if (bAllocNow) { 128 if (bAllocNow) {
130 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); 129 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
131 } 130 }
132 m_nHashTableSize = nHashSize; 131 m_nHashTableSize = nHashSize;
133 } 132 }
134 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) { 133 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) {
135 if (!m_pHashTable) { 134 if (!m_pHashTable) {
136 return FALSE; 135 return FALSE;
137 } 136 }
138 CAssoc** ppAssocPrev; 137 CAssoc** ppAssocPrev;
(...skipping 11 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_basic_list.cpp ('k') | core/fxcrt/fx_extension.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698