Prevented NO-OP calls to the memory allocator

Also shaved off about 1-2 milliseconds of execution time of fib-memo.toy
This commit is contained in:
2023-02-26 21:20:22 +11:00
parent 1064b69d04
commit 624a0c80ba
7 changed files with 44 additions and 25 deletions

View File

@@ -73,7 +73,9 @@ static void adjustEntryCapacity(Toy_private_dictionary_entry** dictionaryHandle,
}
//clear the old array
TOY_FREE_ARRAY(Toy_private_dictionary_entry, *dictionaryHandle, oldCapacity);
if (oldCapacity > 0) {
TOY_FREE_ARRAY(Toy_private_dictionary_entry, *dictionaryHandle, oldCapacity);
}
*dictionaryHandle = newEntries;
}
@@ -133,9 +135,11 @@ void Toy_initLiteralDictionary(Toy_LiteralDictionary* dictionary) {
}
void Toy_freeLiteralDictionary(Toy_LiteralDictionary* dictionary) {
freeEntryArray(dictionary->entries, dictionary->capacity);
dictionary->capacity = 0;
dictionary->contains = 0;
if (dictionary->capacity > 0) {
freeEntryArray(dictionary->entries, dictionary->capacity);
dictionary->capacity = 0;
dictionary->contains = 0;
}
}
void Toy_setLiteralDictionary(Toy_LiteralDictionary* dictionary, Toy_Literal key, Toy_Literal value) {