diff options
Diffstat (limited to 'src/universe.cpp')
-rw-r--r-- | src/universe.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/universe.cpp b/src/universe.cpp index 5fe53d5..5794048 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -36,6 +36,8 @@ THE SOFTWARE. | |||
36 | #include "lane.h" | 36 | #include "lane.h" |
37 | #include "state.h" | 37 | #include "state.h" |
38 | 38 | ||
39 | #include <ranges> | ||
40 | |||
39 | // ################################################################################################# | 41 | // ################################################################################################# |
40 | 42 | ||
41 | Universe::Universe() | 43 | Universe::Universe() |
@@ -124,7 +126,7 @@ void Universe::closeKeepers() | |||
124 | // in that case, the linda operation should do nothing. which means that these operations must check for keeper acquisition success | 126 | // in that case, the linda operation should do nothing. which means that these operations must check for keeper acquisition success |
125 | // which is early-outed with a keepers->nbKeepers null-check | 127 | // which is early-outed with a keepers->nbKeepers null-check |
126 | keepers->nb_keepers = 0; | 128 | keepers->nb_keepers = 0; |
127 | for (int _i = 0; _i < _nbKeepers; ++_i) { | 129 | for (int const _i : std::ranges::iota_view{ 0, _nbKeepers }) { |
128 | lua_State* const _K{ keepers->keeper_array[_i].L }; | 130 | lua_State* const _K{ keepers->keeper_array[_i].L }; |
129 | keepers->keeper_array[_i].L = KeeperState{ nullptr }; | 131 | keepers->keeper_array[_i].L = KeeperState{ nullptr }; |
130 | if (_K != nullptr) { | 132 | if (_K != nullptr) { |
@@ -134,7 +136,7 @@ void Universe::closeKeepers() | |||
134 | _nbKeepers = _i; | 136 | _nbKeepers = _i; |
135 | } | 137 | } |
136 | } | 138 | } |
137 | for (int _i = 0; _i < _nbKeepers; ++_i) { | 139 | for (int const _i : std::ranges::iota_view{ 0, _nbKeepers }) { |
138 | keepers->keeper_array[_i].~Keeper(); | 140 | keepers->keeper_array[_i].~Keeper(); |
139 | } | 141 | } |
140 | // free the keeper bookkeeping structure | 142 | // free the keeper bookkeeping structure |
@@ -225,8 +227,8 @@ void Universe::initializeKeepers(lua_State* L_) | |||
225 | 227 | ||
226 | // Keepers contains an array of 1 Keeper, adjust for the actual number of keeper states | 228 | // Keepers contains an array of 1 Keeper, adjust for the actual number of keeper states |
227 | { | 229 | { |
228 | size_t const bytes = sizeof(Keepers) + (_nb_keepers - 1) * sizeof(Keeper); | 230 | size_t const _bytes{ sizeof(Keepers) + (_nb_keepers - 1) * sizeof(Keeper) }; |
229 | keepers = static_cast<Keepers*>(internalAllocator.alloc(bytes)); | 231 | keepers = static_cast<Keepers*>(internalAllocator.alloc(_bytes)); |
230 | if (keepers == nullptr) { | 232 | if (keepers == nullptr) { |
231 | raise_luaL_error(L_, "out of memory while creating keepers"); | 233 | raise_luaL_error(L_, "out of memory while creating keepers"); |
232 | } | 234 | } |
@@ -234,11 +236,12 @@ void Universe::initializeKeepers(lua_State* L_) | |||
234 | keepers->gc_threshold = keepers_gc_threshold; | 236 | keepers->gc_threshold = keepers_gc_threshold; |
235 | keepers->nb_keepers = _nb_keepers; | 237 | keepers->nb_keepers = _nb_keepers; |
236 | 238 | ||
237 | for (int _i = 0; _i < _nb_keepers; ++_i) { | 239 | for (int const _i : std::ranges::iota_view{ 0, _nb_keepers }) { |
238 | keepers->keeper_array[_i].Keeper::Keeper(); | 240 | keepers->keeper_array[_i].Keeper::Keeper(); |
239 | } | 241 | } |
240 | } | 242 | } |
241 | for (int _i = 0; _i < _nb_keepers; ++_i) { | 243 | |
244 | for (int const _i : std::ranges::iota_view{ 0, _nb_keepers }) { | ||
242 | // note that we will leak K if we raise an error later | 245 | // note that we will leak K if we raise an error later |
243 | KeeperState const _K{ create_state(this, L_) }; // L_: settings K: | 246 | KeeperState const _K{ create_state(this, L_) }; // L_: settings K: |
244 | if (_K == nullptr) { | 247 | if (_K == nullptr) { |