aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-05-28 09:57:54 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-05-28 09:57:54 +0200
commit02fea6561b8ea1a25d740088c4911b584bd763d9 (patch)
tree449317991300551b637512ef2355658c911c1fb5 /src
parent0d3b030eb92657dc276a6188f61e5cfdd7e265cb (diff)
downloadlanes-02fea6561b8ea1a25d740088c4911b584bd763d9.tar.gz
lanes-02fea6561b8ea1a25d740088c4911b584bd763d9.tar.bz2
lanes-02fea6561b8ea1a25d740088c4911b584bd763d9.zip
Sprinkle a bit of std::ranges::iota_view
Diffstat (limited to 'src')
-rw-r--r--src/intercopycontext.cpp6
-rw-r--r--src/keeper.cpp21
-rw-r--r--src/universe.cpp15
3 files changed, 23 insertions, 19 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp
index 893305e..0b4aabc 100644
--- a/src/intercopycontext.cpp
+++ b/src/intercopycontext.cpp
@@ -1273,11 +1273,11 @@ namespace {
1273 InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, _pBuf }; 1273 InterCopyContext _c{ U, L2, L1, CacheIndex{ _top_L2 + 1 }, {}, VT::NORMAL, mode, _pBuf };
1274 bool _copyok{ true }; 1274 bool _copyok{ true };
1275 STACK_CHECK_START_REL(L1, 0); 1275 STACK_CHECK_START_REL(L1, 0);
1276 for (int i{ _top_L1 - n_ + 1 }, j{ 1 }; i <= _top_L1; ++i, ++j) { 1276 for (int _i{ _top_L1 - n_ + 1 }, _j{ 1 }; _i <= _top_L1; ++_i, ++_j) {
1277 if (U->verboseErrors) { 1277 if (U->verboseErrors) {
1278 sprintf(_tmpBuf, "arg_%d", j); 1278 sprintf(_tmpBuf, "arg_%d", _j);
1279 } 1279 }
1280 _c.L1_i = SourceIndex{ i }; 1280 _c.L1_i = SourceIndex{ _i };
1281 _copyok = _c.inter_copy_one(); // L2: ... cache {}n 1281 _copyok = _c.inter_copy_one(); // L2: ... cache {}n
1282 if (!_copyok) { 1282 if (!_copyok) {
1283 break; 1283 break;
diff --git a/src/keeper.cpp b/src/keeper.cpp
index b0ed062..ff5fe26 100644
--- a/src/keeper.cpp
+++ b/src/keeper.cpp
@@ -45,6 +45,7 @@
45 45
46#include <algorithm> 46#include <algorithm>
47#include <cassert> 47#include <cassert>
48#include <ranges>
48 49
49// ################################################################################################# 50// #################################################################################################
50// Keeper implementation 51// Keeper implementation
@@ -112,7 +113,7 @@ static void fifo_push(lua_State* L_, keeper_fifo* fifo_, int count_)
112 int const _idx{ lua_gettop(L_) - count_ }; 113 int const _idx{ lua_gettop(L_) - count_ };
113 int const _start{ fifo_->first + fifo_->count - 1 }; 114 int const _start{ fifo_->first + fifo_->count - 1 };
114 // pop all additional arguments, storing them in the fifo 115 // pop all additional arguments, storing them in the fifo
115 for (int _i = count_; _i >= 1; --_i) { 116 for (int const _i : std::ranges::reverse_view{ std::ranges::iota_view{ 1, count_ + 1 } }) {
116 // store in the fifo the value at the top of the stack at the specified index, popping it from the stack 117 // store in the fifo the value at the top of the stack at the specified index, popping it from the stack
117 lua_rawseti(L_, _idx, _start + _i); 118 lua_rawseti(L_, _idx, _start + _i);
118 } 119 }
@@ -126,10 +127,10 @@ static void fifo_push(lua_State* L_, keeper_fifo* fifo_, int count_)
126// expects exactly 1 value on the stack! 127// expects exactly 1 value on the stack!
127// currently only called with a count of 1, but this may change in the future 128// currently only called with a count of 1, but this may change in the future
128// function assumes that there is enough data in the fifo to satisfy the request 129// function assumes that there is enough data in the fifo to satisfy the request
129static void fifo_peek(lua_State* L_, keeper_fifo* fifo_, int count_) 130static void fifo_peek(lua_State* const L_, keeper_fifo const* const fifo_, int const count_)
130{ 131{
131 STACK_GROW(L_, count_); 132 STACK_GROW(L_, count_);
132 for (int _i = 0; _i < count_; ++_i) { 133 for (int const _i : std::ranges::iota_view{ 0, count_ }) {
133 lua_rawgeti(L_, 1, (fifo_->first + _i)); 134 lua_rawgeti(L_, 1, (fifo_->first + _i));
134 } 135 }
135} 136}
@@ -145,20 +146,20 @@ static void fifo_pop(lua_State* L_, keeper_fifo* fifo_, int count_)
145 // each iteration pushes a value on the stack! 146 // each iteration pushes a value on the stack!
146 STACK_GROW(L_, count_ + 2); 147 STACK_GROW(L_, count_ + 2);
147 // skip first item, we will push it last 148 // skip first item, we will push it last
148 for (int i = 1; i < count_; ++i) { 149 for (int const _i : std::ranges::iota_view{ 1, count_ }) {
149 int const at{ fifo_->first + i }; 150 int const _at{ fifo_->first + _i };
150 // push item on the stack 151 // push item on the stack
151 lua_rawgeti(L_, _fifo_idx, at); // L_: ... fifotbl val 152 lua_rawgeti(L_, _fifo_idx, _at); // L_: ... fifotbl val
152 // remove item from the fifo 153 // remove item from the fifo
153 lua_pushnil(L_); // L_: ... fifotbl val nil 154 lua_pushnil(L_); // L_: ... fifotbl val nil
154 lua_rawseti(L_, _fifo_idx, at); // L_: ... fifotbl val 155 lua_rawseti(L_, _fifo_idx, _at); // L_: ... fifotbl val
155 } 156 }
156 // now process first item 157 // now process first item
157 { 158 {
158 int const at{ fifo_->first }; 159 int const _at{ fifo_->first };
159 lua_rawgeti(L_, _fifo_idx, at); // L_: ... fifotbl vals val 160 lua_rawgeti(L_, _fifo_idx, _at); // L_: ... fifotbl vals val
160 lua_pushnil(L_); // L_: ... fifotbl vals val nil 161 lua_pushnil(L_); // L_: ... fifotbl vals val nil
161 lua_rawseti(L_, _fifo_idx, at); // L_: ... fifotbl vals val 162 lua_rawseti(L_, _fifo_idx, _at); // L_: ... fifotbl vals val
162 lua_replace(L_, _fifo_idx); // L_: ... vals 163 lua_replace(L_, _fifo_idx); // L_: ... vals
163 } 164 }
164 165
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
41Universe::Universe() 43Universe::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) {