Browse Source

Change variable removal to clean up subobjects

pull/8/head
Anton Tarasenko 4 years ago
parent
commit
a90f8995c8
  1. 12
      sources/Data/JSON/JArray.uc
  2. 20
      sources/Data/JSON/JObject.uc
  3. 8
      sources/Data/JSON/JSON.uc

12
sources/Data/JSON/JArray.uc

@ -481,15 +481,27 @@ public final function JArray AddObject()
// Returns `true` if value was actually removed and `false` if it didn't exist.
public final function bool RemoveValue(int index, optional int amount)
{
local int i;
if (index < 0) return false;
if (index >= data.length) return false;
amount = Max(amount, 1);
amount = Min(amount, data.length - index);
for (i = index; i < index + amount; i += 1)
{
if (data[index].complexValue != none) {
data[index].complexValue.Destroy();
}
}
data.Remove(index, amount);
return true;
}
public function Clear()
{
RemoveValue(0, data.length);
}
public function bool IsSubsetOf(JSON rightValue)
{
local int i;

20
sources/Data/JSON/JObject.uc

@ -148,12 +148,17 @@ private final function UpdateProperty(JProperty newProperty)
// Returns `true` if something was actually removed.
private final function bool RemoveProperty(string propertyName)
{
local JProperty propertyToRemove;
local int bucketIndex, propertyIndex;
// Ensure has table was initialized before any updates
if (hashTable.length <= 0) {
UpdateHashTableCapacity();
}
if (FindPropertyIndices(propertyName, bucketIndex, propertyIndex)) {
propertyToRemove = hashTable[bucketIndex].properties[propertyIndex];
if (propertyToRemove.value.complexValue != none) {
propertyToRemove.value.complexValue.Destroy();
}
hashTable[bucketIndex].properties.Remove(propertyIndex, 1);
storedElementCount = Max(0, storedElementCount - 1);
UpdateHashTableCapacity();
@ -640,6 +645,21 @@ protected function string DisplayProperty(
$ displaySettings.afterPropertyValue);
}
public function Clear()
{
local int i, j;
local array<JProperty> nextProperties;
for (i = 0; i < hashTable.length; i += 1)
{
nextProperties = hashTable[i].properties;
for (j = 0; j < nextProperties.length; j += 1)
{
if (nextProperties[j].value.complexValue == none) continue;
nextProperties[j].value.complexValue.Destroy();
}
}
}
defaultproperties
{
ABSOLUTE_LOWER_CAPACITY_LIMIT = 10

8
sources/Data/JSON/JSON.uc

@ -103,6 +103,8 @@ struct JSONDisplaySettings
var private const int MAX_FLOAT_PRECISION;
public function Clear(){}
public function JSON Clone()
{
return none;
@ -481,6 +483,12 @@ protected final function JStorageAtom ParseNumber(Parser parser)
return newAtom;
}
event Destroyed()
{
super.Destroyed();
Clear();
}
defaultproperties
{
MAX_FLOAT_PRECISION = 4

Loading…
Cancel
Save