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

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

Issue 372473003: Remove custom memory manager (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Change malloc to calloc Created 6 years, 5 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_list.cpp ('k') | core/src/fxcrt/fx_basic_memmgr.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 "../../include/fxcrt/fx_ext.h" 7 #include "../../include/fxcrt/fx_ext.h"
8 #include "plex.h" 8 #include "plex.h"
9 static void ConstructElement(CFX_ByteString* pNewData) 9 static void ConstructElement(CFX_ByteString* pNewData)
10 { 10 {
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 { 14 {
15 pOldData->~CFX_ByteString(); 15 pOldData->~CFX_ByteString();
16 } 16 }
17 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize, IFX_Allocator* pAllocator) 17 CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
18 : m_pAllocator(pAllocator) 18 : m_pHashTable(NULL)
19 , m_pHashTable(NULL)
20 , m_nHashTableSize(17) 19 , m_nHashTableSize(17)
21 , m_nCount(0) 20 , m_nCount(0)
22 , m_pFreeList(NULL) 21 , m_pFreeList(NULL)
23 , m_pBlocks(NULL) 22 , m_pBlocks(NULL)
24 , m_nBlockSize(nBlockSize) 23 , m_nBlockSize(nBlockSize)
25 { 24 {
26 ASSERT(m_nBlockSize > 0); 25 ASSERT(m_nBlockSize > 0);
27 } 26 }
28 void CFX_MapPtrToPtr::RemoveAll() 27 void CFX_MapPtrToPtr::RemoveAll()
29 { 28 {
30 if (m_pHashTable) { 29 if (m_pHashTable) {
31 FX_Allocator_Free(m_pAllocator, m_pHashTable); 30 FX_Free(m_pHashTable);
32 m_pHashTable = NULL; 31 m_pHashTable = NULL;
33 } 32 }
34 m_nCount = 0; 33 m_nCount = 0;
35 m_pFreeList = NULL; 34 m_pFreeList = NULL;
36 m_pBlocks->FreeDataChain(m_pAllocator); 35 m_pBlocks->FreeDataChain();
37 m_pBlocks = NULL; 36 m_pBlocks = NULL;
38 } 37 }
39 CFX_MapPtrToPtr::~CFX_MapPtrToPtr() 38 CFX_MapPtrToPtr::~CFX_MapPtrToPtr()
40 { 39 {
41 RemoveAll(); 40 RemoveAll();
42 ASSERT(m_nCount == 0); 41 ASSERT(m_nCount == 0);
43 } 42 }
44 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const 43 FX_DWORD CFX_MapPtrToPtr::HashKey(void* key) const
45 { 44 {
46 return ((FX_DWORD)(FX_UINTPTR)key) >> 4; 45 return ((FX_DWORD)(FX_UINTPTR)key) >> 4;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if (pAssoc->key == key) { 114 if (pAssoc->key == key) {
116 return pAssoc; 115 return pAssoc;
117 } 116 }
118 } 117 }
119 return NULL; 118 return NULL;
120 } 119 }
121 CFX_MapPtrToPtr::CAssoc* 120 CFX_MapPtrToPtr::CAssoc*
122 CFX_MapPtrToPtr::NewAssoc() 121 CFX_MapPtrToPtr::NewAssoc()
123 { 122 {
124 if (m_pFreeList == NULL) { 123 if (m_pFreeList == NULL) {
125 CFX_Plex* newBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockS ize, sizeof(CFX_MapPtrToPtr::CAssoc)); 124 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CF X_MapPtrToPtr::CAssoc));
126 CFX_MapPtrToPtr::CAssoc* pAssoc = (CFX_MapPtrToPtr::CAssoc*)newBlock->da ta(); 125 CFX_MapPtrToPtr::CAssoc* pAssoc = (CFX_MapPtrToPtr::CAssoc*)newBlock->da ta();
127 pAssoc += m_nBlockSize - 1; 126 pAssoc += m_nBlockSize - 1;
128 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { 127 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
129 pAssoc->pNext = m_pFreeList; 128 pAssoc->pNext = m_pFreeList;
130 m_pFreeList = pAssoc; 129 m_pFreeList = pAssoc;
131 } 130 }
132 } 131 }
133 ASSERT(m_pFreeList != NULL); 132 ASSERT(m_pFreeList != NULL);
134 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList; 133 CFX_MapPtrToPtr::CAssoc* pAssoc = m_pFreeList;
135 m_pFreeList = m_pFreeList->pNext; 134 m_pFreeList = m_pFreeList->pNext;
136 m_nCount++; 135 m_nCount++;
137 ASSERT(m_nCount > 0); 136 ASSERT(m_nCount > 0);
138 pAssoc->key = 0; 137 pAssoc->key = 0;
139 pAssoc->value = 0; 138 pAssoc->value = 0;
140 return pAssoc; 139 return pAssoc;
141 } 140 }
142 void CFX_MapPtrToPtr::InitHashTable( 141 void CFX_MapPtrToPtr::InitHashTable(
143 FX_DWORD nHashSize, FX_BOOL bAllocNow) 142 FX_DWORD nHashSize, FX_BOOL bAllocNow)
144 { 143 {
145 ASSERT(m_nCount == 0); 144 ASSERT(m_nCount == 0);
146 ASSERT(nHashSize > 0); 145 ASSERT(nHashSize > 0);
147 if (m_pHashTable != NULL) { 146 if (m_pHashTable != NULL) {
148 FX_Allocator_Free(m_pAllocator, m_pHashTable); 147 FX_Free(m_pHashTable);
149 m_pHashTable = NULL; 148 m_pHashTable = NULL;
150 } 149 }
151 if (bAllocNow) { 150 if (bAllocNow) {
152 m_pHashTable = FX_Allocator_Alloc(m_pAllocator, CAssoc*, nHashSize); 151 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
153 if (m_pHashTable) {
154 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize);
155 }
156 } 152 }
157 m_nHashTableSize = nHashSize; 153 m_nHashTableSize = nHashSize;
158 } 154 }
159 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) 155 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key)
160 { 156 {
161 if (m_pHashTable == NULL) { 157 if (m_pHashTable == NULL) {
162 return FALSE; 158 return FALSE;
163 } 159 }
164 CAssoc** ppAssocPrev; 160 CAssoc** ppAssocPrev;
165 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize]; 161 ppAssocPrev = &m_pHashTable[HashKey(key) % m_nHashTableSize];
(...skipping 11 matching lines...) Expand all
177 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) 173 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc)
178 { 174 {
179 pAssoc->pNext = m_pFreeList; 175 pAssoc->pNext = m_pFreeList;
180 m_pFreeList = pAssoc; 176 m_pFreeList = pAssoc;
181 m_nCount--; 177 m_nCount--;
182 ASSERT(m_nCount >= 0); 178 ASSERT(m_nCount >= 0);
183 if (m_nCount == 0) { 179 if (m_nCount == 0) {
184 RemoveAll(); 180 RemoveAll();
185 } 181 }
186 } 182 }
187 CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize, IFX_Allocator* pA llocator) 183 CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize)
188 : m_pAllocator(pAllocator) 184 : m_pHashTable(NULL)
189 , m_pHashTable(NULL)
190 , m_nHashTableSize(17) 185 , m_nHashTableSize(17)
191 , m_nCount(0) 186 , m_nCount(0)
192 , m_pFreeList(NULL) 187 , m_pFreeList(NULL)
193 , m_pBlocks(NULL) 188 , m_pBlocks(NULL)
194 , m_nBlockSize(nBlockSize) 189 , m_nBlockSize(nBlockSize)
195 { 190 {
196 ASSERT(m_nBlockSize > 0); 191 ASSERT(m_nBlockSize > 0);
197 } 192 }
198 void CFX_MapByteStringToPtr::RemoveAll() 193 void CFX_MapByteStringToPtr::RemoveAll()
199 { 194 {
200 if (m_pHashTable != NULL) { 195 if (m_pHashTable != NULL) {
201 for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) { 196 for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) {
202 CAssoc* pAssoc; 197 CAssoc* pAssoc;
203 for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; 198 for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL;
204 pAssoc = pAssoc->pNext) { 199 pAssoc = pAssoc->pNext) {
205 DestructElement(&pAssoc->key); 200 DestructElement(&pAssoc->key);
206 } 201 }
207 } 202 }
208 FX_Allocator_Free(m_pAllocator, m_pHashTable); 203 FX_Free(m_pHashTable);
209 m_pHashTable = NULL; 204 m_pHashTable = NULL;
210 } 205 }
211 m_nCount = 0; 206 m_nCount = 0;
212 m_pFreeList = NULL; 207 m_pFreeList = NULL;
213 m_pBlocks->FreeDataChain(m_pAllocator); 208 m_pBlocks->FreeDataChain();
214 m_pBlocks = NULL; 209 m_pBlocks = NULL;
215 } 210 }
216 CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr() 211 CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr()
217 { 212 {
218 RemoveAll(); 213 RemoveAll();
219 ASSERT(m_nCount == 0); 214 ASSERT(m_nCount == 0);
220 } 215 }
221 void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, 216 void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
222 CFX_ByteString& rKey, void*& rValue) const 217 CFX_ByteString& rKey, void*& rValue) const
223 { 218 {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 pAssoc->key = key; 274 pAssoc->key = key;
280 pAssoc->pNext = m_pHashTable[nHash]; 275 pAssoc->pNext = m_pHashTable[nHash];
281 m_pHashTable[nHash] = pAssoc; 276 m_pHashTable[nHash] = pAssoc;
282 } 277 }
283 return pAssoc->value; 278 return pAssoc->value;
284 } 279 }
285 CFX_MapByteStringToPtr::CAssoc* 280 CFX_MapByteStringToPtr::CAssoc*
286 CFX_MapByteStringToPtr::NewAssoc() 281 CFX_MapByteStringToPtr::NewAssoc()
287 { 282 {
288 if (m_pFreeList == NULL) { 283 if (m_pFreeList == NULL) {
289 CFX_Plex* newBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockS ize, sizeof(CFX_MapByteStringToPtr::CAssoc)); 284 CFX_Plex* newBlock = CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CF X_MapByteStringToPtr::CAssoc));
290 CFX_MapByteStringToPtr::CAssoc* pAssoc = (CFX_MapByteStringToPtr::CAssoc *)newBlock->data(); 285 CFX_MapByteStringToPtr::CAssoc* pAssoc = (CFX_MapByteStringToPtr::CAssoc *)newBlock->data();
291 pAssoc += m_nBlockSize - 1; 286 pAssoc += m_nBlockSize - 1;
292 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { 287 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) {
293 pAssoc->pNext = m_pFreeList; 288 pAssoc->pNext = m_pFreeList;
294 m_pFreeList = pAssoc; 289 m_pFreeList = pAssoc;
295 } 290 }
296 } 291 }
297 ASSERT(m_pFreeList != NULL); 292 ASSERT(m_pFreeList != NULL);
298 CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList; 293 CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList;
299 m_pFreeList = m_pFreeList->pNext; 294 m_pFreeList = m_pFreeList->pNext;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 333 }
339 rValue = pAssoc->value; 334 rValue = pAssoc->value;
340 return TRUE; 335 return TRUE;
341 } 336 }
342 void CFX_MapByteStringToPtr::InitHashTable( 337 void CFX_MapByteStringToPtr::InitHashTable(
343 FX_DWORD nHashSize, FX_BOOL bAllocNow) 338 FX_DWORD nHashSize, FX_BOOL bAllocNow)
344 { 339 {
345 ASSERT(m_nCount == 0); 340 ASSERT(m_nCount == 0);
346 ASSERT(nHashSize > 0); 341 ASSERT(nHashSize > 0);
347 if (m_pHashTable != NULL) { 342 if (m_pHashTable != NULL) {
348 FX_Allocator_Free(m_pAllocator, m_pHashTable); 343 FX_Free(m_pHashTable);
349 m_pHashTable = NULL; 344 m_pHashTable = NULL;
350 } 345 }
351 if (bAllocNow) { 346 if (bAllocNow) {
352 m_pHashTable = FX_Allocator_Alloc(m_pAllocator, CAssoc*, nHashSize); 347 m_pHashTable = FX_Alloc(CAssoc*, nHashSize);
353 if (m_pHashTable) {
354 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize);
355 }
356 } 348 }
357 m_nHashTableSize = nHashSize; 349 m_nHashTableSize = nHashSize;
358 } 350 }
359 inline FX_DWORD CFX_MapByteStringToPtr::HashKey(FX_BSTR key) const 351 inline FX_DWORD CFX_MapByteStringToPtr::HashKey(FX_BSTR key) const
360 { 352 {
361 FX_DWORD nHash = 0; 353 FX_DWORD nHash = 0;
362 int len = key.GetLength(); 354 int len = key.GetLength();
363 FX_LPCBYTE buf = key; 355 FX_LPCBYTE buf = key;
364 for (int i = 0; i < len; i ++) { 356 for (int i = 0; i < len; i ++) {
365 nHash = (nHash << 5) + nHash + buf[i]; 357 nHash = (nHash << 5) + nHash + buf[i];
(...skipping 18 matching lines...) Expand all
384 } 376 }
385 return FALSE; 377 return FALSE;
386 } 378 }
387 struct _CompactString { 379 struct _CompactString {
388 FX_BYTE m_CompactLen; 380 FX_BYTE m_CompactLen;
389 FX_BYTE m_LenHigh; 381 FX_BYTE m_LenHigh;
390 FX_BYTE m_LenLow; 382 FX_BYTE m_LenLow;
391 FX_BYTE m_Unused; 383 FX_BYTE m_Unused;
392 FX_LPBYTE m_pBuffer; 384 FX_LPBYTE m_pBuffer;
393 }; 385 };
394 static void _CompactStringRelease(IFX_Allocator* pAllocator, _CompactString* pCo mpact) 386 static void _CompactStringRelease(_CompactString* pCompact)
395 { 387 {
396 if (pCompact->m_CompactLen == 0xff) { 388 if (pCompact->m_CompactLen == 0xff) {
397 FX_Allocator_Free(pAllocator, pCompact->m_pBuffer); 389 FX_Free(pCompact->m_pBuffer);
398 } 390 }
399 } 391 }
400 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int len) 392 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int len)
401 { 393 {
402 if (len < sizeof(_CompactString)) { 394 if (len < sizeof(_CompactString)) {
403 if (pCompact->m_CompactLen != len) { 395 if (pCompact->m_CompactLen != len) {
404 return FALSE; 396 return FALSE;
405 } 397 }
406 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0; 398 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0;
407 } 399 }
408 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact-> m_LenLow != len) { 400 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact-> m_LenLow != len) {
409 return FALSE; 401 return FALSE;
410 } 402 }
411 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0; 403 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0;
412 } 404 }
413 static void _CompactStringStore(IFX_Allocator* pAllocator, _CompactString* pComp act, FX_LPCBYTE pStr, int len) 405 static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int l en)
414 { 406 {
415 if (len < (int)sizeof(_CompactString)) { 407 if (len < (int)sizeof(_CompactString)) {
416 pCompact->m_CompactLen = (FX_BYTE)len; 408 pCompact->m_CompactLen = (FX_BYTE)len;
417 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len); 409 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len);
418 return; 410 return;
419 } 411 }
420 pCompact->m_CompactLen = 0xff; 412 pCompact->m_CompactLen = 0xff;
421 pCompact->m_LenHigh = len / 256; 413 pCompact->m_LenHigh = len / 256;
422 pCompact->m_LenLow = len % 256; 414 pCompact->m_LenLow = len % 256;
423 pCompact->m_pBuffer = FX_Allocator_Alloc(pAllocator, FX_BYTE, len); 415 pCompact->m_pBuffer = FX_Alloc(FX_BYTE, len);
424 if (pCompact->m_pBuffer) { 416 if (pCompact->m_pBuffer) {
425 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); 417 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len);
426 } 418 }
427 } 419 }
428 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) 420 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact)
429 { 421 {
430 if (pCompact->m_CompactLen == 0xff) { 422 if (pCompact->m_CompactLen == 0xff) {
431 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 + pCompact->m_LenLow); 423 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 + pCompact->m_LenLow);
432 } 424 }
433 if (pCompact->m_CompactLen == 0xfe) { 425 if (pCompact->m_CompactLen == 0xfe) {
434 return CFX_ByteStringC(); 426 return CFX_ByteStringC();
435 } 427 }
436 return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen); 428 return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen);
437 } 429 }
438 #define CMAP_ALLOC_STEP 8 430 #define CMAP_ALLOC_STEP 8
439 #define CMAP_INDEX_SIZE 8 431 #define CMAP_INDEX_SIZE 8
440 CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator) 432 CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr()
441 : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_IND EX_SIZE, pAllocator) 433 : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_IND EX_SIZE)
442 { 434 {
443 } 435 }
444 CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr() 436 CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr()
445 { 437 {
446 RemoveAll(); 438 RemoveAll();
447 } 439 }
448 void CFX_CMapByteStringToPtr::RemoveAll() 440 void CFX_CMapByteStringToPtr::RemoveAll()
449 { 441 {
450 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
451 int size = m_Buffer.GetSize(); 442 int size = m_Buffer.GetSize();
452 for (int i = 0; i < size; i ++) { 443 for (int i = 0; i < size; i++) {
453 _CompactStringRelease(pAllocator, (_CompactString*)m_Buffer.GetAt(i)); 444 _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i));
454 } 445 }
455 m_Buffer.RemoveAll(); 446 m_Buffer.RemoveAll();
456 } 447 }
457 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const 448 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const
458 { 449 {
459 int size = m_Buffer.GetSize(); 450 int size = m_Buffer.GetSize();
460 for (int i = 0; i < size; i ++) { 451 for (int i = 0; i < size; i ++) {
461 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); 452 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
462 if (pKey->m_CompactLen != 0xfe) { 453 if (pKey->m_CompactLen != 0xfe) {
463 return (FX_POSITION)(FX_UINTPTR)(i + 1); 454 return (FX_POSITION)(FX_UINTPTR)(i + 1);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 int index, key_len = key.GetLength(); 517 int index, key_len = key.GetLength();
527 int size = m_Buffer.GetSize(); 518 int size = m_Buffer.GetSize();
528 for (index = 0; index < size; index ++) { 519 for (index = 0; index < size; index ++) {
529 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); 520 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
530 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { 521 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) {
531 continue; 522 continue;
532 } 523 }
533 *(void**)(pKey + 1) = value; 524 *(void**)(pKey + 1) = value;
534 return; 525 return;
535 } 526 }
536 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
537 for (index = 0; index < size; index ++) { 527 for (index = 0; index < size; index ++) {
538 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); 528 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
539 if (pKey->m_CompactLen) { 529 if (pKey->m_CompactLen) {
540 continue; 530 continue;
541 } 531 }
542 _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len); 532 _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
543 *(void**)(pKey + 1) = value; 533 *(void**)(pKey + 1) = value;
544 return; 534 return;
545 } 535 }
546 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); 536 _CompactString* pKey = (_CompactString*)m_Buffer.Add();
547 _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len); 537 _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len);
548 *(void**)(pKey + 1) = value; 538 *(void**)(pKey + 1) = value;
549 } 539 }
550 void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value) 540 void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value)
551 { 541 {
552 ASSERT(value != NULL); 542 ASSERT(value != NULL);
553 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); 543 _CompactString* pKey = (_CompactString*)m_Buffer.Add();
554 _CompactStringStore(m_Buffer.m_pAllocator, pKey, (FX_LPCBYTE)key, key.GetLen gth()); 544 _CompactStringStore(pKey, (FX_LPCBYTE)key, key.GetLength());
555 *(void**)(pKey + 1) = value; 545 *(void**)(pKey + 1) = value;
556 } 546 }
557 void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key) 547 void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key)
558 { 548 {
559 int key_len = key.GetLength(); 549 int key_len = key.GetLength();
560 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator;
561 int size = m_Buffer.GetSize(); 550 int size = m_Buffer.GetSize();
562 for (int index = 0; index < size; index ++) { 551 for (int index = 0; index < size; index++) {
563 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); 552 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
564 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { 553 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) {
565 continue; 554 continue;
566 } 555 }
567 _CompactStringRelease(pAllocator, pKey); 556 _CompactStringRelease(pKey);
568 pKey->m_CompactLen = 0xfe; 557 pKey->m_CompactLen = 0xfe;
569 return; 558 return;
570 } 559 }
571 } 560 }
572 int CFX_CMapByteStringToPtr::GetCount() const 561 int CFX_CMapByteStringToPtr::GetCount() const
573 { 562 {
574 int count = 0; 563 int count = 0;
575 int size = m_Buffer.GetSize(); 564 int size = m_Buffer.GetSize();
576 for (int i = 0; i < size; i ++) { 565 for (int i = 0; i < size; i ++) {
577 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); 566 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 buf[mid].value = value; 634 buf[mid].value = value;
646 return; 635 return;
647 } 636 }
648 } 637 }
649 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); 638 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair));
650 } 639 }
651 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) 640 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by)
652 { 641 {
653 m_Buffer.EstimateSize(size, grow_by); 642 m_Buffer.EstimateSize(size, grow_by);
654 } 643 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_list.cpp ('k') | core/src/fxcrt/fx_basic_memmgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698