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

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

Issue 1297713003: Don't bother checking pointers before delete[] and FX_Free(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 4 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/src/fxcrt/fx_basic_buffer.cpp ('k') | core/src/fxcrt/xml_int.h » ('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 "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 #include "plex.h" 8 #include "plex.h"
9 9
10 static void ConstructElement(CFX_ByteString* pNewData) { 10 static void ConstructElement(CFX_ByteString* pNewData) {
11 new (pNewData) CFX_ByteString(); 11 new (pNewData) CFX_ByteString();
12 } 12 }
13 static void DestructElement(CFX_ByteString* pOldData) { 13 static void DestructElement(CFX_ByteString* pOldData) {
14 pOldData->~CFX_ByteString(); 14 pOldData->~CFX_ByteString();
15 } 15 }
16 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize) 16 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
17 : m_pHashTable(NULL), 17 : m_pHashTable(NULL),
18 m_nHashTableSize(17), 18 m_nHashTableSize(17),
19 m_nCount(0), 19 m_nCount(0),
20 m_pFreeList(NULL), 20 m_pFreeList(NULL),
21 m_pBlocks(NULL), 21 m_pBlocks(NULL),
22 m_nBlockSize(nBlockSize) { 22 m_nBlockSize(nBlockSize) {
23 ASSERT(m_nBlockSize > 0); 23 ASSERT(m_nBlockSize > 0);
24 } 24 }
25 void CFX_MapPtrToPtr::RemoveAll() { 25 void CFX_MapPtrToPtr::RemoveAll() {
26 if (m_pHashTable) { 26 FX_Free(m_pHashTable);
27 FX_Free(m_pHashTable); 27 m_pHashTable = NULL;
28 m_pHashTable = NULL;
29 }
30 m_nCount = 0; 28 m_nCount = 0;
31 m_pFreeList = NULL; 29 m_pFreeList = NULL;
32 m_pBlocks->FreeDataChain(); 30 m_pBlocks->FreeDataChain();
33 m_pBlocks = NULL; 31 m_pBlocks = NULL;
34 } 32 }
35 CFX_MapPtrToPtr::~CFX_MapPtrToPtr() { 33 CFX_MapPtrToPtr::~CFX_MapPtrToPtr() {
36 RemoveAll(); 34 RemoveAll();
37 ASSERT(m_nCount == 0); 35 ASSERT(m_nCount == 0);
38 } 36 }
39 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const { 37 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 m_pFreeList = m_pFreeList->pNext; 125 m_pFreeList = m_pFreeList->pNext;
128 m_nCount++; 126 m_nCount++;
129 ASSERT(m_nCount > 0); 127 ASSERT(m_nCount > 0);
130 pAssoc->key = 0; 128 pAssoc->key = 0;
131 pAssoc->value = 0; 129 pAssoc->value = 0;
132 return pAssoc; 130 return pAssoc;
133 } 131 }
134 void CFX_MapPtrToPtr::InitHashTable(FX_DWORD nHashSize, FX_BOOL bAllocNow) { 132 void CFX_MapPtrToPtr::InitHashTable(FX_DWORD nHashSize, FX_BOOL bAllocNow) {
135 ASSERT(m_nCount == 0); 133 ASSERT(m_nCount == 0);
136 ASSERT(nHashSize > 0); 134 ASSERT(nHashSize > 0);
137 if (m_pHashTable != NULL) { 135 FX_Free(m_pHashTable);
138 FX_Free(m_pHashTable); 136 m_pHashTable = NULL;
139 m_pHashTable = NULL;
140 }
141 if (bAllocNow) { 137 if (bAllocNow) {
142 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); 138 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
143 } 139 }
144 m_nHashTableSize = nHashSize; 140 m_nHashTableSize = nHashSize;
145 } 141 }
146 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) { 142 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) {
147 if (m_pHashTable == NULL) { 143 if (m_pHashTable == NULL) {
148 return FALSE; 144 return FALSE;
149 } 145 }
150 CAssoc** ppAssocPrev; 146 CAssoc** ppAssocPrev;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 if (pAssoc == NULL) { 310 if (pAssoc == NULL) {
315 return FALSE; 311 return FALSE;
316 } 312 }
317 rValue = pAssoc->value; 313 rValue = pAssoc->value;
318 return TRUE; 314 return TRUE;
319 } 315 }
320 void CFX_MapByteStringToPtr::InitHashTable(FX_DWORD nHashSize, 316 void CFX_MapByteStringToPtr::InitHashTable(FX_DWORD nHashSize,
321 FX_BOOL bAllocNow) { 317 FX_BOOL bAllocNow) {
322 ASSERT(m_nCount == 0); 318 ASSERT(m_nCount == 0);
323 ASSERT(nHashSize > 0); 319 ASSERT(nHashSize > 0);
324 if (m_pHashTable != NULL) { 320 FX_Free(m_pHashTable);
325 FX_Free(m_pHashTable); 321 m_pHashTable = NULL;
326 m_pHashTable = NULL;
327 }
328 if (bAllocNow) { 322 if (bAllocNow) {
329 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); 323 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
330 } 324 }
331 m_nHashTableSize = nHashSize; 325 m_nHashTableSize = nHashSize;
332 } 326 }
333 inline FX_DWORD CFX_MapByteStringToPtr::HashKey( 327 inline FX_DWORD CFX_MapByteStringToPtr::HashKey(
334 const CFX_ByteStringC& key) const { 328 const CFX_ByteStringC& key) const {
335 FX_DWORD nHash = 0; 329 FX_DWORD nHash = 0;
336 int len = key.GetLength(); 330 int len = key.GetLength();
337 const uint8_t* buf = key.GetPtr(); 331 const uint8_t* buf = key.GetPtr();
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } else { 601 } else {
608 buf[mid].value = value; 602 buf[mid].value = value;
609 return; 603 return;
610 } 604 }
611 } 605 }
612 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); 606 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair));
613 } 607 }
614 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) { 608 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) {
615 m_Buffer.EstimateSize(size, grow_by); 609 m_Buffer.EstimateSize(size, grow_by);
616 } 610 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_buffer.cpp ('k') | core/src/fxcrt/xml_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698