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 "../../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 Loading... |
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) { | 152 if (m_pHashTable) { |
154 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize); | 153 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize); |
155 } | 154 } |
156 } | 155 } |
157 m_nHashTableSize = nHashSize; | 156 m_nHashTableSize = nHashSize; |
158 } | 157 } |
159 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) | 158 FX_BOOL CFX_MapPtrToPtr::RemoveKey(void* key) |
160 { | 159 { |
161 if (m_pHashTable == NULL) { | 160 if (m_pHashTable == NULL) { |
162 return FALSE; | 161 return FALSE; |
(...skipping 14 matching lines...) Expand all Loading... |
177 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) | 176 void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) |
178 { | 177 { |
179 pAssoc->pNext = m_pFreeList; | 178 pAssoc->pNext = m_pFreeList; |
180 m_pFreeList = pAssoc; | 179 m_pFreeList = pAssoc; |
181 m_nCount--; | 180 m_nCount--; |
182 ASSERT(m_nCount >= 0); | 181 ASSERT(m_nCount >= 0); |
183 if (m_nCount == 0) { | 182 if (m_nCount == 0) { |
184 RemoveAll(); | 183 RemoveAll(); |
185 } | 184 } |
186 } | 185 } |
187 CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize, IFX_Allocator* pA
llocator) | 186 CFX_MapByteStringToPtr::CFX_MapByteStringToPtr(int nBlockSize) |
188 : m_pAllocator(pAllocator) | 187 : m_pHashTable(NULL) |
189 , m_pHashTable(NULL) | |
190 , m_nHashTableSize(17) | 188 , m_nHashTableSize(17) |
191 , m_nCount(0) | 189 , m_nCount(0) |
192 , m_pFreeList(NULL) | 190 , m_pFreeList(NULL) |
193 , m_pBlocks(NULL) | 191 , m_pBlocks(NULL) |
194 , m_nBlockSize(nBlockSize) | 192 , m_nBlockSize(nBlockSize) |
195 { | 193 { |
196 ASSERT(m_nBlockSize > 0); | 194 ASSERT(m_nBlockSize > 0); |
197 } | 195 } |
198 void CFX_MapByteStringToPtr::RemoveAll() | 196 void CFX_MapByteStringToPtr::RemoveAll() |
199 { | 197 { |
200 if (m_pHashTable != NULL) { | 198 if (m_pHashTable != NULL) { |
201 for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) { | 199 for (FX_DWORD nHash = 0; nHash < m_nHashTableSize; nHash++) { |
202 CAssoc* pAssoc; | 200 CAssoc* pAssoc; |
203 for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; | 201 for (pAssoc = m_pHashTable[nHash]; pAssoc != NULL; |
204 pAssoc = pAssoc->pNext) { | 202 pAssoc = pAssoc->pNext) { |
205 DestructElement(&pAssoc->key); | 203 DestructElement(&pAssoc->key); |
206 } | 204 } |
207 } | 205 } |
208 FX_Allocator_Free(m_pAllocator, m_pHashTable); | 206 FX_Free(m_pHashTable); |
209 m_pHashTable = NULL; | 207 m_pHashTable = NULL; |
210 } | 208 } |
211 m_nCount = 0; | 209 m_nCount = 0; |
212 m_pFreeList = NULL; | 210 m_pFreeList = NULL; |
213 m_pBlocks->FreeDataChain(m_pAllocator); | 211 m_pBlocks->FreeDataChain(); |
214 m_pBlocks = NULL; | 212 m_pBlocks = NULL; |
215 } | 213 } |
216 CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr() | 214 CFX_MapByteStringToPtr::~CFX_MapByteStringToPtr() |
217 { | 215 { |
218 RemoveAll(); | 216 RemoveAll(); |
219 ASSERT(m_nCount == 0); | 217 ASSERT(m_nCount == 0); |
220 } | 218 } |
221 void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, | 219 void CFX_MapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition, |
222 CFX_ByteString& rKey, void*& rValue) const | 220 CFX_ByteString& rKey, void*& rValue) const |
223 { | 221 { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 pAssoc->key = key; | 277 pAssoc->key = key; |
280 pAssoc->pNext = m_pHashTable[nHash]; | 278 pAssoc->pNext = m_pHashTable[nHash]; |
281 m_pHashTable[nHash] = pAssoc; | 279 m_pHashTable[nHash] = pAssoc; |
282 } | 280 } |
283 return pAssoc->value; | 281 return pAssoc->value; |
284 } | 282 } |
285 CFX_MapByteStringToPtr::CAssoc* | 283 CFX_MapByteStringToPtr::CAssoc* |
286 CFX_MapByteStringToPtr::NewAssoc() | 284 CFX_MapByteStringToPtr::NewAssoc() |
287 { | 285 { |
288 if (m_pFreeList == NULL) { | 286 if (m_pFreeList == NULL) { |
289 CFX_Plex* newBlock = CFX_Plex::Create(m_pAllocator, m_pBlocks, m_nBlockS
ize, sizeof(CFX_MapByteStringToPtr::CAssoc)); | 287 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(); | 288 CFX_MapByteStringToPtr::CAssoc* pAssoc = (CFX_MapByteStringToPtr::CAssoc
*)newBlock->data(); |
291 pAssoc += m_nBlockSize - 1; | 289 pAssoc += m_nBlockSize - 1; |
292 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { | 290 for (int i = m_nBlockSize - 1; i >= 0; i--, pAssoc--) { |
293 pAssoc->pNext = m_pFreeList; | 291 pAssoc->pNext = m_pFreeList; |
294 m_pFreeList = pAssoc; | 292 m_pFreeList = pAssoc; |
295 } | 293 } |
296 } | 294 } |
297 ASSERT(m_pFreeList != NULL); | 295 ASSERT(m_pFreeList != NULL); |
298 CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList; | 296 CFX_MapByteStringToPtr::CAssoc* pAssoc = m_pFreeList; |
299 m_pFreeList = m_pFreeList->pNext; | 297 m_pFreeList = m_pFreeList->pNext; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 336 } |
339 rValue = pAssoc->value; | 337 rValue = pAssoc->value; |
340 return TRUE; | 338 return TRUE; |
341 } | 339 } |
342 void CFX_MapByteStringToPtr::InitHashTable( | 340 void CFX_MapByteStringToPtr::InitHashTable( |
343 FX_DWORD nHashSize, FX_BOOL bAllocNow) | 341 FX_DWORD nHashSize, FX_BOOL bAllocNow) |
344 { | 342 { |
345 ASSERT(m_nCount == 0); | 343 ASSERT(m_nCount == 0); |
346 ASSERT(nHashSize > 0); | 344 ASSERT(nHashSize > 0); |
347 if (m_pHashTable != NULL) { | 345 if (m_pHashTable != NULL) { |
348 FX_Allocator_Free(m_pAllocator, m_pHashTable); | 346 FX_Free(m_pHashTable); |
349 m_pHashTable = NULL; | 347 m_pHashTable = NULL; |
350 } | 348 } |
351 if (bAllocNow) { | 349 if (bAllocNow) { |
352 m_pHashTable = FX_Allocator_Alloc(m_pAllocator, CAssoc*, nHashSize); | 350 m_pHashTable = FX_Alloc(CAssoc*, nHashSize); |
353 if (m_pHashTable) { | 351 if (m_pHashTable) { |
354 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize); | 352 FXSYS_memset32(m_pHashTable, 0, sizeof(CAssoc*) * nHashSize); |
355 } | 353 } |
356 } | 354 } |
357 m_nHashTableSize = nHashSize; | 355 m_nHashTableSize = nHashSize; |
358 } | 356 } |
359 inline FX_DWORD CFX_MapByteStringToPtr::HashKey(FX_BSTR key) const | 357 inline FX_DWORD CFX_MapByteStringToPtr::HashKey(FX_BSTR key) const |
360 { | 358 { |
361 FX_DWORD nHash = 0; | 359 FX_DWORD nHash = 0; |
362 int len = key.GetLength(); | 360 int len = key.GetLength(); |
(...skipping 21 matching lines...) Expand all Loading... |
384 } | 382 } |
385 return FALSE; | 383 return FALSE; |
386 } | 384 } |
387 struct _CompactString { | 385 struct _CompactString { |
388 FX_BYTE m_CompactLen; | 386 FX_BYTE m_CompactLen; |
389 FX_BYTE m_LenHigh; | 387 FX_BYTE m_LenHigh; |
390 FX_BYTE m_LenLow; | 388 FX_BYTE m_LenLow; |
391 FX_BYTE m_Unused; | 389 FX_BYTE m_Unused; |
392 FX_LPBYTE m_pBuffer; | 390 FX_LPBYTE m_pBuffer; |
393 }; | 391 }; |
394 static void _CompactStringRelease(IFX_Allocator* pAllocator, _CompactString* pCo
mpact) | 392 static void _CompactStringRelease(_CompactString* pCompact) |
395 { | 393 { |
396 if (pCompact->m_CompactLen == 0xff) { | 394 if (pCompact->m_CompactLen == 0xff) { |
397 FX_Allocator_Free(pAllocator, pCompact->m_pBuffer); | 395 FX_Free(pCompact->m_pBuffer); |
398 } | 396 } |
399 } | 397 } |
400 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int
len) | 398 static FX_BOOL _CompactStringSame(_CompactString* pCompact, FX_LPCBYTE pStr, int
len) |
401 { | 399 { |
402 if (len < sizeof(_CompactString)) { | 400 if (len < sizeof(_CompactString)) { |
403 if (pCompact->m_CompactLen != len) { | 401 if (pCompact->m_CompactLen != len) { |
404 return FALSE; | 402 return FALSE; |
405 } | 403 } |
406 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0; | 404 return FXSYS_memcmp32(&pCompact->m_LenHigh, pStr, len) == 0; |
407 } | 405 } |
408 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact->
m_LenLow != len) { | 406 if (pCompact->m_CompactLen != 0xff || pCompact->m_LenHigh * 256 + pCompact->
m_LenLow != len) { |
409 return FALSE; | 407 return FALSE; |
410 } | 408 } |
411 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0; | 409 return FXSYS_memcmp32(pCompact->m_pBuffer, pStr, len) == 0; |
412 } | 410 } |
413 static void _CompactStringStore(IFX_Allocator* pAllocator, _CompactString* pComp
act, FX_LPCBYTE pStr, int len) | 411 static void _CompactStringStore(_CompactString* pCompact, FX_LPCBYTE pStr, int l
en) |
414 { | 412 { |
415 if (len < (int)sizeof(_CompactString)) { | 413 if (len < (int)sizeof(_CompactString)) { |
416 pCompact->m_CompactLen = (FX_BYTE)len; | 414 pCompact->m_CompactLen = (FX_BYTE)len; |
417 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len); | 415 FXSYS_memcpy32(&pCompact->m_LenHigh, pStr, len); |
418 return; | 416 return; |
419 } | 417 } |
420 pCompact->m_CompactLen = 0xff; | 418 pCompact->m_CompactLen = 0xff; |
421 pCompact->m_LenHigh = len / 256; | 419 pCompact->m_LenHigh = len / 256; |
422 pCompact->m_LenLow = len % 256; | 420 pCompact->m_LenLow = len % 256; |
423 pCompact->m_pBuffer = FX_Allocator_Alloc(pAllocator, FX_BYTE, len); | 421 pCompact->m_pBuffer = FX_Alloc(FX_BYTE, len); |
424 if (pCompact->m_pBuffer) { | 422 if (pCompact->m_pBuffer) { |
425 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); | 423 FXSYS_memcpy32(pCompact->m_pBuffer, pStr, len); |
426 } | 424 } |
427 } | 425 } |
428 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) | 426 static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) |
429 { | 427 { |
430 if (pCompact->m_CompactLen == 0xff) { | 428 if (pCompact->m_CompactLen == 0xff) { |
431 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 +
pCompact->m_LenLow); | 429 return CFX_ByteStringC(pCompact->m_pBuffer, pCompact->m_LenHigh * 256 +
pCompact->m_LenLow); |
432 } | 430 } |
433 if (pCompact->m_CompactLen == 0xfe) { | 431 if (pCompact->m_CompactLen == 0xfe) { |
434 return CFX_ByteStringC(); | 432 return CFX_ByteStringC(); |
435 } | 433 } |
436 return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen); | 434 return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen); |
437 } | 435 } |
438 #define CMAP_ALLOC_STEP 8 | 436 #define CMAP_ALLOC_STEP 8 |
439 #define CMAP_INDEX_SIZE 8 | 437 #define CMAP_INDEX_SIZE 8 |
440 CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr(IFX_Allocator* pAllocator) | 438 CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr() |
441 : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_IND
EX_SIZE, pAllocator) | 439 : m_Buffer(sizeof(_CompactString) + sizeof(void*), CMAP_ALLOC_STEP, CMAP_IND
EX_SIZE) |
442 { | 440 { |
443 } | 441 } |
444 CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr() | 442 CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr() |
445 { | 443 { |
446 RemoveAll(); | 444 RemoveAll(); |
447 } | 445 } |
448 void CFX_CMapByteStringToPtr::RemoveAll() | 446 void CFX_CMapByteStringToPtr::RemoveAll() |
449 { | 447 { |
450 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator; | |
451 int size = m_Buffer.GetSize(); | 448 int size = m_Buffer.GetSize(); |
452 for (int i = 0; i < size; i ++) { | 449 for (int i = 0; i < size; i++) { |
453 _CompactStringRelease(pAllocator, (_CompactString*)m_Buffer.GetAt(i)); | 450 _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i)); |
454 } | 451 } |
455 m_Buffer.RemoveAll(); | 452 m_Buffer.RemoveAll(); |
456 } | 453 } |
457 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const | 454 FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const |
458 { | 455 { |
459 int size = m_Buffer.GetSize(); | 456 int size = m_Buffer.GetSize(); |
460 for (int i = 0; i < size; i ++) { | 457 for (int i = 0; i < size; i ++) { |
461 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); | 458 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); |
462 if (pKey->m_CompactLen != 0xfe) { | 459 if (pKey->m_CompactLen != 0xfe) { |
463 return (FX_POSITION)(FX_UINTPTR)(i + 1); | 460 return (FX_POSITION)(FX_UINTPTR)(i + 1); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 int index, key_len = key.GetLength(); | 523 int index, key_len = key.GetLength(); |
527 int size = m_Buffer.GetSize(); | 524 int size = m_Buffer.GetSize(); |
528 for (index = 0; index < size; index ++) { | 525 for (index = 0; index < size; index ++) { |
529 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); | 526 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); |
530 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { | 527 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { |
531 continue; | 528 continue; |
532 } | 529 } |
533 *(void**)(pKey + 1) = value; | 530 *(void**)(pKey + 1) = value; |
534 return; | 531 return; |
535 } | 532 } |
536 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator; | |
537 for (index = 0; index < size; index ++) { | 533 for (index = 0; index < size; index ++) { |
538 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); | 534 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); |
539 if (pKey->m_CompactLen) { | 535 if (pKey->m_CompactLen) { |
540 continue; | 536 continue; |
541 } | 537 } |
542 _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len); | 538 _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len); |
543 *(void**)(pKey + 1) = value; | 539 *(void**)(pKey + 1) = value; |
544 return; | 540 return; |
545 } | 541 } |
546 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); | 542 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); |
547 _CompactStringStore(pAllocator, pKey, (FX_LPCBYTE)key, key_len); | 543 _CompactStringStore(pKey, (FX_LPCBYTE)key, key_len); |
548 *(void**)(pKey + 1) = value; | 544 *(void**)(pKey + 1) = value; |
549 } | 545 } |
550 void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value) | 546 void CFX_CMapByteStringToPtr::AddValue(FX_BSTR key, void* value) |
551 { | 547 { |
552 ASSERT(value != NULL); | 548 ASSERT(value != NULL); |
553 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); | 549 _CompactString* pKey = (_CompactString*)m_Buffer.Add(); |
554 _CompactStringStore(m_Buffer.m_pAllocator, pKey, (FX_LPCBYTE)key, key.GetLen
gth()); | 550 _CompactStringStore(pKey, (FX_LPCBYTE)key, key.GetLength()); |
555 *(void**)(pKey + 1) = value; | 551 *(void**)(pKey + 1) = value; |
556 } | 552 } |
557 void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key) | 553 void CFX_CMapByteStringToPtr::RemoveKey(FX_BSTR key) |
558 { | 554 { |
559 int key_len = key.GetLength(); | 555 int key_len = key.GetLength(); |
560 IFX_Allocator* pAllocator = m_Buffer.m_pAllocator; | |
561 int size = m_Buffer.GetSize(); | 556 int size = m_Buffer.GetSize(); |
562 for (int index = 0; index < size; index ++) { | 557 for (int index = 0; index < size; index++) { |
563 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); | 558 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index); |
564 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { | 559 if (!_CompactStringSame(pKey, (FX_LPCBYTE)key, key_len)) { |
565 continue; | 560 continue; |
566 } | 561 } |
567 _CompactStringRelease(pAllocator, pKey); | 562 _CompactStringRelease(pKey); |
568 pKey->m_CompactLen = 0xfe; | 563 pKey->m_CompactLen = 0xfe; |
569 return; | 564 return; |
570 } | 565 } |
571 } | 566 } |
572 int CFX_CMapByteStringToPtr::GetCount() const | 567 int CFX_CMapByteStringToPtr::GetCount() const |
573 { | 568 { |
574 int count = 0; | 569 int count = 0; |
575 int size = m_Buffer.GetSize(); | 570 int size = m_Buffer.GetSize(); |
576 for (int i = 0; i < size; i ++) { | 571 for (int i = 0; i < size; i ++) { |
577 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); | 572 _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 buf[mid].value = value; | 640 buf[mid].value = value; |
646 return; | 641 return; |
647 } | 642 } |
648 } | 643 } |
649 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); | 644 m_Buffer.InsertBlock(low * sizeof(_DWordPair), &pair, sizeof(_DWordPair)); |
650 } | 645 } |
651 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) | 646 void CFX_CMapDWordToDWord::EstimateSize(FX_DWORD size, FX_DWORD grow_by) |
652 { | 647 { |
653 m_Buffer.EstimateSize(size, grow_by); | 648 m_Buffer.EstimateSize(size, grow_by); |
654 } | 649 } |
OLD | NEW |