mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use std::array for TemporaryStorageArray.
This removes the need for initialisation with memset().
This commit is contained in:
parent
9040d7813d
commit
7bd019df90
|
@ -131,17 +131,12 @@ struct PersistentStorageArray : BasePersistentStorageArray {
|
||||||
*/
|
*/
|
||||||
template <typename TYPE, uint SIZE>
|
template <typename TYPE, uint SIZE>
|
||||||
struct TemporaryStorageArray {
|
struct TemporaryStorageArray {
|
||||||
TYPE storage[SIZE]; ///< Memory to for the storage array
|
using StorageType = std::array<TYPE, SIZE>;
|
||||||
uint16_t init[SIZE]; ///< Storage has been assigned, if this equals 'init_key'.
|
using StorageInitType = std::array<uint16_t, SIZE>;
|
||||||
uint16_t init_key; ///< Magic key to 'init'.
|
|
||||||
|
|
||||||
/** Simply construct the array */
|
StorageType storage{}; ///< Memory for the storage array
|
||||||
TemporaryStorageArray()
|
StorageInitType init{}; ///< Storage has been assigned, if this equals 'init_key'.
|
||||||
{
|
uint16_t init_key{1}; ///< Magic key to 'init'.
|
||||||
memset(this->storage, 0, sizeof(this->storage)); // not exactly needed, but makes code analysers happy
|
|
||||||
memset(this->init, 0, sizeof(this->init));
|
|
||||||
this->init_key = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores some value at a given position.
|
* Stores some value at a given position.
|
||||||
|
@ -181,7 +176,7 @@ struct TemporaryStorageArray {
|
||||||
this->init_key++;
|
this->init_key++;
|
||||||
if (this->init_key == 0) {
|
if (this->init_key == 0) {
|
||||||
/* When init_key wraps around, we need to reset everything */
|
/* When init_key wraps around, we need to reset everything */
|
||||||
memset(this->init, 0, sizeof(this->init));
|
this->init = {};
|
||||||
this->init_key = 1;
|
this->init_key = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue