mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-05-01 22:40:10 +10:00
BUGFIX: scopes weren't expanding as intended
This commit is contained in:
+7
-1
@@ -85,11 +85,12 @@ static Toy_ScopeEntry* adjustScopeEntries(Toy_Scope* scope, unsigned int newCapa
|
|||||||
return newEntries;
|
return newEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
//movethe old data into the new block of memory
|
//move the old data into the new block of memory
|
||||||
unsigned int oldCapacity = scope->capacity;
|
unsigned int oldCapacity = scope->capacity;
|
||||||
Toy_ScopeEntry* oldEntries = scope->data;
|
Toy_ScopeEntry* oldEntries = scope->data;
|
||||||
scope->capacity = newCapacity;
|
scope->capacity = newCapacity;
|
||||||
scope->data = newEntries;
|
scope->data = newEntries;
|
||||||
|
scope->count = 0;
|
||||||
|
|
||||||
//for each existing entry in the old array, copy it into the new array
|
//for each existing entry in the old array, copy it into the new array
|
||||||
for (unsigned int i = 0; i < oldCapacity; i++) {
|
for (unsigned int i = 0; i < oldCapacity; i++) {
|
||||||
@@ -146,6 +147,11 @@ void Toy_declareScope(Toy_Scope* scope, Toy_String* key, Toy_ValueType type, Toy
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//expand the table capacity if needed
|
||||||
|
if (scope->count >= scope->capacity * 0.8f) {
|
||||||
|
scope->data = adjustScopeEntries(scope, scope->capacity * TOY_SCOPE_EXPANSION_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
value = coerceValueTypesIfAble(type, value);
|
value = coerceValueTypesIfAble(type, value);
|
||||||
|
|
||||||
//type check
|
//type check
|
||||||
|
|||||||
+1
-1
@@ -52,5 +52,5 @@ TOY_API void Toy_private_decrementScopeRefCount(Toy_Scope* scope);
|
|||||||
|
|
||||||
//expand when the contents passes a certain percentage (80%) of the capacity
|
//expand when the contents passes a certain percentage (80%) of the capacity
|
||||||
#ifndef TOY_SCOPE_EXPANSION_THRESHOLD
|
#ifndef TOY_SCOPE_EXPANSION_THRESHOLD
|
||||||
#define TOY_SCOPE_EXPANSION_THRESHOLD 0.8f
|
#define TOY_SCOPE_EXPANSION_THRESHOLD 0.7f
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -40,5 +40,5 @@ TOY_API Toy_TableEntry* Toy_private_lookupTableEntryPtr(Toy_Table** tableHandle,
|
|||||||
|
|
||||||
//expand when the contents passes a certain percentage (80%) of the capacity
|
//expand when the contents passes a certain percentage (80%) of the capacity
|
||||||
#ifndef TOY_TABLE_EXPANSION_THRESHOLD
|
#ifndef TOY_TABLE_EXPANSION_THRESHOLD
|
||||||
#define TOY_TABLE_EXPANSION_THRESHOLD 0.8f
|
#define TOY_TABLE_EXPANSION_THRESHOLD 0.7f
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -586,7 +586,7 @@ int test_table_expansions_under_stress(void) {
|
|||||||
|
|
||||||
//check the state
|
//check the state
|
||||||
if (table == NULL ||
|
if (table == NULL ||
|
||||||
table->capacity != 512 ||
|
table->capacity != 1024 ||
|
||||||
table->count != 400 ||
|
table->count != 400 ||
|
||||||
|
|
||||||
TOY_VALUE_IS_INTEGER(result) != true ||
|
TOY_VALUE_IS_INTEGER(result) != true ||
|
||||||
|
|||||||
Reference in New Issue
Block a user