Skip to content

Commit

Permalink
Save a lookup when erasing addCbRefs
Browse files Browse the repository at this point in the history
  • Loading branch information
animetosho committed Apr 5, 2024
1 parent 6b4bb3b commit 9fb9a1d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gf16/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ bool PAR2Proc::_addInput(const void* buffer, size_t size, uint16_t inputRef, T i
cbRef = addCbRefs.emplace(std::make_pair(inputRef, PAR2ProcAddCbRef{
(int)backends.size(), cb,
[this, inputRef]() {
auto& ref = addCbRefs[inputRef];
auto itRef = addCbRefs.find(inputRef);
auto& ref = itRef->second;
if(--ref.backendsActive == 0) {
auto cb = ref.cb;
addCbRefs.erase(inputRef);
addCbRefs.erase(itRef);
if(cb) cb();
}
}
Expand Down Expand Up @@ -213,6 +214,7 @@ bool PAR2Proc::_addInput(const void* buffer, size_t size, uint16_t inputRef, T i
hasAdded = true;
for(auto& backend : backends)
backend.added.erase(inputRef);
// have seen the above line segfault in qemu-user RV64, but not if changed to `backend.added.erase(backend.added.find(inputRef))` - don't understand why, maybe dodgy C++ runtime?
}
return success;
}
Expand Down

0 comments on commit 9fb9a1d

Please sign in to comment.