Browse Source

Remove life version checks from `ArrayList`

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
65c6706062
  1. 24
      sources/Data/Collections/ArrayList.uc

24
sources/Data/Collections/ArrayList.uc

@ -26,10 +26,6 @@ class ArrayList extends Collection;
// Actual storage of all our data.
var private array<AcediaObject> storedObjects;
// Recorded `lifeVersions` of all stored objects.
// Invariant `lifeVersions.length == storedObjects.length` should be
// enforced by all methods.
var private array<int> lifeVersions;
// Free array data
protected function Finalizer()
@ -78,7 +74,6 @@ public final function ArrayList SetLength(int newLength)
FreeItem(i);
}
storedObjects.length = newLength;
lifeVersions.length = newLength;
return self;
}
@ -95,7 +90,7 @@ protected final function ArrayList FreeItem(int index)
if (storedObjects[index] == none) {
return self;
}
storedObjects[index].FreeSelf(lifeVersions[index]);
storedObjects[index].FreeSelf();
storedObjects[index] = none;
return self;
}
@ -176,10 +171,6 @@ protected final function Swap(int index1, int index2)
temporaryItem = storedObjects[index1];
storedObjects[index1] = storedObjects[index2];
storedObjects[index2] = temporaryItem;
// Swap life versions
temporaryNumber = lifeVersions[index1];
lifeVersions[index1] = lifeVersions[index2];
lifeVersions[index2] = temporaryNumber;
}
/**
@ -209,7 +200,6 @@ public final function ArrayList Remove(int index, int count)
FreeItem(index + i);
}
storedObjects.Remove(index, count);
lifeVersions.Remove(index, count);
return self;
}
@ -234,8 +224,7 @@ public final function ArrayList RemoveIndex(int index)
* reference.
*
* @param index Index of an item to validate/
* @return `true` if `index` is valid for `storedObjects` / `lifeVersions`
* and there is no need to check it.
* @return `true` if `index` is valid for `storedObjects` array.
*/
private final function bool ValidateIndex(int index)
{
@ -244,13 +233,7 @@ private final function bool ValidateIndex(int index)
if (index < 0) return false;
if (index >= storedObjects.length) return false;
item = storedObjects[index];
if (item == none) return true;
if (item.GetLifeVersion() != lifeVersions[index])
{
storedObjects[index] = none;
lifeVersions[index] = 0;
}
return true;
}
@ -269,7 +252,6 @@ public final function AcediaObject TakeItem(int index)
{
result = storedObjects[index];
storedObjects[index] = none;
lifeVersions[index] = 0;
}
return result;
}
@ -303,7 +285,6 @@ public final function AcediaObject GetItem(int index)
{
result = storedObjects[index];
storedObjects[index] = none;
lifeVersions[index] = 0;
}
if (result != none) {
result.NewRef();
@ -335,7 +316,6 @@ public final function ArrayList SetItem(int index, AcediaObject item)
{
item.NewRef();
storedObjects[index] = item;
lifeVersions[index] = item.GetLifeVersion();
}
return self;
}

Loading…
Cancel
Save