summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/fxcrt/fx_basic_maps.cpp196
1 files changed, 0 insertions, 196 deletions
diff --git a/core/src/fxcrt/fx_basic_maps.cpp b/core/src/fxcrt/fx_basic_maps.cpp
index f7d127f7da..d9b634e649 100644
--- a/core/src/fxcrt/fx_basic_maps.cpp
+++ b/core/src/fxcrt/fx_basic_maps.cpp
@@ -7,13 +7,6 @@
#include "core/include/fxcrt/fx_basic.h"
#include "plex.h"
-namespace {
-
-const uint8_t kFreeLength = 0xfe;
-const uint8_t kHasAllocatedBufferLength = 0xff;
-
-} // namespace
-
CFX_MapPtrToPtr::CFX_MapPtrToPtr(int nBlockSize)
: m_pHashTable(NULL),
m_nHashTableSize(17),
@@ -164,192 +157,3 @@ void CFX_MapPtrToPtr::FreeAssoc(CFX_MapPtrToPtr::CAssoc* pAssoc) {
RemoveAll();
}
}
-struct _CompactString {
- uint8_t m_CompactLen;
- uint8_t m_LenHigh;
- uint8_t m_LenLow;
- uint8_t m_Unused;
- uint8_t* m_pBuffer;
-};
-static void _CompactStringRelease(_CompactString* pCompact) {
- if (pCompact->m_CompactLen == kHasAllocatedBufferLength) {
- FX_Free(pCompact->m_pBuffer);
- }
-}
-static FX_BOOL _CompactStringSame(_CompactString* pCompact,
- const uint8_t* pStr,
- int len) {
- if (len < sizeof(_CompactString)) {
- if (pCompact->m_CompactLen != len) {
- return FALSE;
- }
- return FXSYS_memcmp(&pCompact->m_LenHigh, pStr, len) == 0;
- }
- if (pCompact->m_CompactLen != kHasAllocatedBufferLength ||
- pCompact->m_LenHigh * 256 + pCompact->m_LenLow != len) {
- return FALSE;
- }
- return FXSYS_memcmp(pCompact->m_pBuffer, pStr, len) == 0;
-}
-static void _CompactStringStore(_CompactString* pCompact,
- const uint8_t* pStr,
- int len) {
- if (len < (int)sizeof(_CompactString)) {
- pCompact->m_CompactLen = (uint8_t)len;
- FXSYS_memcpy(&pCompact->m_LenHigh, pStr, len);
- return;
- }
- pCompact->m_CompactLen = kHasAllocatedBufferLength;
- pCompact->m_LenHigh = len / 256;
- pCompact->m_LenLow = len % 256;
- pCompact->m_pBuffer = FX_Alloc(uint8_t, len);
- FXSYS_memcpy(pCompact->m_pBuffer, pStr, len);
-}
-static CFX_ByteStringC _CompactStringGet(_CompactString* pCompact) {
- if (pCompact->m_CompactLen == kHasAllocatedBufferLength) {
- return CFX_ByteStringC(pCompact->m_pBuffer,
- pCompact->m_LenHigh * 256 + pCompact->m_LenLow);
- }
- if (pCompact->m_CompactLen == kFreeLength) {
- return CFX_ByteStringC();
- }
- return CFX_ByteStringC(&pCompact->m_LenHigh, pCompact->m_CompactLen);
-}
-#define CMAP_ALLOC_STEP 8
-#define CMAP_INDEX_SIZE 8
-CFX_CMapByteStringToPtr::CFX_CMapByteStringToPtr()
- : m_Buffer(sizeof(_CompactString) + sizeof(void*),
- CMAP_ALLOC_STEP,
- CMAP_INDEX_SIZE) {}
-CFX_CMapByteStringToPtr::~CFX_CMapByteStringToPtr() {
- RemoveAll();
-}
-void CFX_CMapByteStringToPtr::RemoveAll() {
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactStringRelease((_CompactString*)m_Buffer.GetAt(i));
- }
- m_Buffer.RemoveAll();
-}
-FX_POSITION CFX_CMapByteStringToPtr::GetStartPosition() const {
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
- if (pKey->m_CompactLen != kFreeLength) {
- return (FX_POSITION)(uintptr_t)(i + 1);
- }
- }
- return NULL;
-}
-void CFX_CMapByteStringToPtr::GetNextAssoc(FX_POSITION& rNextPosition,
- CFX_ByteString& rKey,
- void*& rValue) const {
- if (!rNextPosition) {
- return;
- }
- int index = (int)(uintptr_t)rNextPosition - 1;
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- rKey = _CompactStringGet(pKey);
- rValue = *(void**)(pKey + 1);
- index++;
- int size = m_Buffer.GetSize();
- while (index < size) {
- pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- rNextPosition = (FX_POSITION)(uintptr_t)(index + 1);
- return;
- }
- index++;
- }
- rNextPosition = NULL;
-}
-void* CFX_CMapByteStringToPtr::GetNextValue(FX_POSITION& rNextPosition) const {
- if (!rNextPosition) {
- return NULL;
- }
- int index = (int)(uintptr_t)rNextPosition - 1;
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- void* rValue = *(void**)(pKey + 1);
- index++;
- int size = m_Buffer.GetSize();
- while (index < size) {
- pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- rNextPosition = (FX_POSITION)(uintptr_t)(index + 1);
- return rValue;
- }
- index++;
- }
- rNextPosition = NULL;
- return rValue;
-}
-FX_BOOL _CMapLookupCallback(void* param, void* pData) {
- return !_CompactStringSame((_CompactString*)pData,
- ((CFX_ByteStringC*)param)->GetPtr(),
- ((CFX_ByteStringC*)param)->GetLength());
-}
-FX_BOOL CFX_CMapByteStringToPtr::Lookup(const CFX_ByteStringC& key,
- void*& rValue) const {
- void* p = m_Buffer.Iterate(_CMapLookupCallback, (void*)&key);
- if (!p) {
- return FALSE;
- }
- rValue = *(void**)((_CompactString*)p + 1);
- return TRUE;
-}
-void CFX_CMapByteStringToPtr::SetAt(const CFX_ByteStringC& key, void* value) {
- ASSERT(value);
- int key_len = key.GetLength();
- int size = m_Buffer.GetSize();
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
- continue;
- }
- *(void**)(pKey + 1) = value;
- return;
- }
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (pKey->m_CompactLen != kFreeLength) {
- continue;
- }
- _CompactStringStore(pKey, key.GetPtr(), key_len);
- *(void**)(pKey + 1) = value;
- return;
- }
- _CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, key.GetPtr(), key_len);
- *(void**)(pKey + 1) = value;
-}
-void CFX_CMapByteStringToPtr::AddValue(const CFX_ByteStringC& key,
- void* value) {
- ASSERT(value);
- _CompactString* pKey = (_CompactString*)m_Buffer.Add();
- _CompactStringStore(pKey, key.GetPtr(), key.GetLength());
- *(void**)(pKey + 1) = value;
-}
-void CFX_CMapByteStringToPtr::RemoveKey(const CFX_ByteStringC& key) {
- int key_len = key.GetLength();
- int size = m_Buffer.GetSize();
- for (int index = 0; index < size; index++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(index);
- if (!_CompactStringSame(pKey, key.GetPtr(), key_len)) {
- continue;
- }
- _CompactStringRelease(pKey);
- pKey->m_CompactLen = kFreeLength;
- return;
- }
-}
-int CFX_CMapByteStringToPtr::GetCount() const {
- int count = 0;
- int size = m_Buffer.GetSize();
- for (int i = 0; i < size; i++) {
- _CompactString* pKey = (_CompactString*)m_Buffer.GetAt(i);
- if (pKey->m_CompactLen != kFreeLength) {
- count++;
- }
- }
- return count;
-}