Skip to content

Commit 01e0c98

Browse files
authored
Avoid usedElements around code that modifys that value (#3488)
Followup to #3486, I wonder if it isn't a little more clear this way, which avoids the confusion of usedElements being changed while we are using it. In general I think it's best to only use usedElements in the most internal methods, and to call size() otherwise.
1 parent fcbefa9 commit 01e0c98

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/mixed_arena.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,21 @@ template<typename SubType, typename T> class ArenaVectorBase {
368368
// C-API
369369

370370
void insertAt(size_t index, T item) {
371-
assert(index <= usedElements); // appending is ok
372-
resize(usedElements + 1);
373-
for (auto i = usedElements - 1; i > index; --i) {
371+
assert(index <= size()); // appending is ok
372+
resize(size() + 1);
373+
for (auto i = size() - 1; i > index; --i) {
374374
data[i] = data[i - 1];
375375
}
376376
data[index] = item;
377377
}
378378

379379
T removeAt(size_t index) {
380-
assert(index < usedElements);
380+
assert(index < size());
381381
auto item = data[index];
382-
for (auto i = index; i < usedElements - 1; ++i) {
382+
for (auto i = index; i < size() - 1; ++i) {
383383
data[i] = data[i + 1];
384384
}
385-
resize(usedElements - 1);
385+
resize(size() - 1);
386386
return item;
387387
}
388388
};

0 commit comments

Comments
 (0)