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

Loading…
Cancel
Save