@@ -75,25 +75,25 @@ struct PersistentStorageArray : BaseStor
* @param value the value to write
*/
void StoreValue(uint pos, int32 value)
{
/* Out of the scope of the array */
if (pos >= SIZE) return;
/* The value hasn't changed, so we pretend nothing happened.
* Saves a few cycles and such and it's pretty easy to check. */
if (this->storage[pos] == value) return;
/* We do not have made a backup; lets do so */
if (this->prev_storage != NULL) {
if (this->prev_storage == NULL) {
this->prev_storage = MallocT<TYPE>(SIZE);
memcpy(this->prev_storage, this->storage, sizeof(this->storage));
/* We only need to register ourselves when we made the backup
* as that is the only time something will have changed */
AddChangedStorage(this);
}
this->storage[pos] = value;
/**
@@ -112,24 +112,25 @@ struct PersistentStorageArray : BaseStor
* Clear the changes, or assign them permanently to the storage.
* @param keep_changes Whether to assign or ditch the changes.
void ClearChanges(bool keep_changes)
assert(this->prev_storage != NULL);
if (!keep_changes) {
memcpy(this->storage, this->prev_storage, sizeof(this->storage));
free(this->prev_storage);
this->prev_storage = NULL;
};
* Class for temporary storage of data.
* On #ClearChanges that data is always zero-ed.
* @tparam TYPE the type of variable to store.
* @tparam SIZE the size of the array.
template <typename TYPE, uint SIZE>
struct TemporaryStorageArray : BaseStorageArray {
Status change: