diff options
author | Alon Zakai <azakai@google.com> | 2021-01-14 16:43:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 08:43:56 -0800 |
commit | 01e0c98eb75ed389441ada253bcf02dbc8f1f6ef (patch) | |
tree | 47fbe85701555eee891d24d29c05794947f6fde0 /src/mixed_arena.h | |
parent | fcbefa951e3e514f6b7555664b89fb786850f6bc (diff) | |
download | binaryen-01e0c98eb75ed389441ada253bcf02dbc8f1f6ef.tar.gz binaryen-01e0c98eb75ed389441ada253bcf02dbc8f1f6ef.tar.bz2 binaryen-01e0c98eb75ed389441ada253bcf02dbc8f1f6ef.zip |
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.
Diffstat (limited to 'src/mixed_arena.h')
-rw-r--r-- | src/mixed_arena.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/mixed_arena.h b/src/mixed_arena.h index b4822680b..4d2e24542 100644 --- a/src/mixed_arena.h +++ b/src/mixed_arena.h @@ -368,21 +368,21 @@ public: // C-API void insertAt(size_t index, T item) { - assert(index <= usedElements); // appending is ok - resize(usedElements + 1); - for (auto i = usedElements - 1; i > index; --i) { + assert(index <= size()); // appending is ok + resize(size() + 1); + for (auto i = size() - 1; i > index; --i) { data[i] = data[i - 1]; } data[index] = item; } T removeAt(size_t index) { - assert(index < usedElements); + assert(index < size()); auto item = data[index]; - for (auto i = index; i < usedElements - 1; ++i) { + for (auto i = index; i < size() - 1; ++i) { data[i] = data[i + 1]; } - resize(usedElements - 1); + resize(size() - 1); return item; } }; |