Skip to content

Commit

Permalink
Move completed transactions more efficiently with std::list::splice
Browse files Browse the repository at this point in the history
  • Loading branch information
dgelessus committed Sep 17, 2023
1 parent 86576c5 commit bd6b2b2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglTrans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,19 @@ void NetTransUpdate () {
for (auto it = s_transactions.begin(); it != s_transactions.end();) {
NetTrans* trans = *it;
// Increment a copy of the iterator here already,
// because the original iterator may be invalidated by an erase call below.
// because the original iterator's meaning may be changed by a splice call below.
auto next = it;
next++;

bool done = false;
while (!done) {
switch (trans->m_state) {
case kTransStateComplete:
s_transactions.erase(it);
// Move the completed transaction out of s_transactions.
if (trans->m_hasSubTrans) {
parentCompleted.push_back(trans);
parentCompleted.splice(parentCompleted.end(), s_transactions, it);
} else {
completed.push_back(trans);
completed.splice(completed.end(), s_transactions, it);
}
done = true;
break;
Expand Down

0 comments on commit bd6b2b2

Please sign in to comment.