From c6095b96d9ca33f95858b3d70641573dd878f1ec Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Sat, 18 Jun 2022 16:16:32 +0300 Subject: [PATCH] Cleanup dictionary.h See #42 --- src/dictionary.cc | 24 +++++++++++++++++------- src/dictionary.h | 13 ------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/dictionary.cc b/src/dictionary.cc index f49ba03..b7ef061 100644 --- a/src/dictionary.cc +++ b/src/dictionary.cc @@ -6,29 +6,39 @@ #include #include +// NOTE: I guess this marker is used as a type discriminator for implementing +// nested dictionaries. That's why every dictionary-related function starts +// with a check for this value. +#define DICTIONARY_MARKER 0xFEBAFEBA + +static void* dictionaryMallocDefaultImpl(size_t size); +static void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize); +static void dictionaryFreeDefaultImpl(void* ptr); +static int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* index); + // 0x51E408 -MallocProc* gDictionaryMallocProc = dictionaryMallocDefaultImpl; +static MallocProc* gDictionaryMallocProc = dictionaryMallocDefaultImpl; // 0x51E40C -ReallocProc* gDictionaryReallocProc = dictionaryReallocDefaultImpl; +static ReallocProc* gDictionaryReallocProc = dictionaryReallocDefaultImpl; // 0x51E410 -FreeProc* gDictionaryFreeProc = dictionaryFreeDefaultImpl; +static FreeProc* gDictionaryFreeProc = dictionaryFreeDefaultImpl; // 0x4D9B90 -void* dictionaryMallocDefaultImpl(size_t size) +static void* dictionaryMallocDefaultImpl(size_t size) { return malloc(size); } // 0x4D9B98 -void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize) +static void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize) { return realloc(ptr, newSize); } // 0x4D9BA0 -void dictionaryFreeDefaultImpl(void* ptr) +static void dictionaryFreeDefaultImpl(void* ptr) { free(ptr); } @@ -127,7 +137,7 @@ int dictionaryFree(Dictionary* dictionary) // specifies an insertion point for given key. // // 0x4D9CC4 -int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* indexPtr) +static int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* indexPtr) { if (dictionary->marker != DICTIONARY_MARKER) { return -1; diff --git a/src/dictionary.h b/src/dictionary.h index 28b5d2a..b3e35ad 100644 --- a/src/dictionary.h +++ b/src/dictionary.h @@ -3,11 +3,6 @@ #include "memory_defs.h" -// NOTE: I guess this marker is used as a type discriminator for implementing -// nested dictionaries. That's why every dictionary-related function starts -// with a check for this value. -#define DICTIONARY_MARKER 0xFEBAFEBA - // A tuple containing individual key-value pair of a dictionary. typedef struct DictionaryEntry { char* key; @@ -42,17 +37,9 @@ typedef struct Dictionary { DictionaryEntry* entries; } Dictionary; -extern MallocProc* gDictionaryMallocProc; -extern ReallocProc* gDictionaryReallocProc; -extern FreeProc* gDictionaryFreeProc; - -void* dictionaryMallocDefaultImpl(size_t size); -void* dictionaryReallocDefaultImpl(void* ptr, size_t newSize); -void dictionaryFreeDefaultImpl(void* ptr); int dictionaryInit(Dictionary* dictionary, int initialCapacity, size_t valueSize, void* a4); int dictionarySetCapacity(Dictionary* dictionary, int newCapacity); int dictionaryFree(Dictionary* dictionary); -int dictionaryFindIndexForKey(Dictionary* dictionary, const char* key, int* index); int dictionaryGetIndexByKey(Dictionary* dictionary, const char* key); int dictionaryAddValue(Dictionary* dictionary, const char* key, const void* value); int dictionaryRemoveValue(Dictionary* dictionary, const char* key);