From: <sv...@op...> - 2024-03-23 14:10:14
|
Author: sagamusix Date: Sat Mar 23 15:09:57 2024 New Revision: 20426 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20426 Log: Merged revision(s) 20424 from trunk/OpenMPT: [Imp] Avoid re-allocating the loop state map contents on every playthrough. For libopenmpt, the contents of patterns can never change anyway. For OpenMPT, this may in theory cause new allocations to be made during playback if the user inserted some pattern loops while playback was happening, but those allocations would happen anyway at the time the song loops, we cannot avoid them. ........ Modified: branches/OpenMPT-1.30/ (props changed) branches/OpenMPT-1.30/soundlib/RowVisitor.cpp Modified: branches/OpenMPT-1.30/soundlib/RowVisitor.cpp ============================================================================== --- branches/OpenMPT-1.30/soundlib/RowVisitor.cpp Sat Mar 23 15:09:39 2024 (r20425) +++ branches/OpenMPT-1.30/soundlib/RowVisitor.cpp Sat Mar 23 15:09:57 2024 (r20426) @@ -23,7 +23,7 @@ RowVisitor::LoopState::LoopState(const ChannelStates &chnState, const bool ignoreRow) { - // Rather than storing the exact loop count vector, we compute a FNV-1a 64-bit hash of it. + // Rather than storing the exact loop count vector, we compute an FNV-1a 64-bit hash of it. // This means we can store the loop state in a small and fixed amount of memory. // In theory there is the possibility of hash collisions for different loop states, but in practice, // the relevant inputs for the hashing algorithm are extremely unlikely to produce collisions. @@ -84,10 +84,15 @@ { auto &order = Order(); const ORDERINDEX endOrder = order.GetLengthTailTrimmed(); + bool reserveLoopStates = true; m_visitedRows.resize(endOrder); if(reset) { - m_visitedLoopStates.clear(); + reserveLoopStates = m_visitedLoopStates.empty(); + for(auto &loopState : m_visitedLoopStates) + { + loopState.second.clear(); + } m_rowsSpentInLoops = 0; } @@ -104,7 +109,7 @@ else visitedRows.resize(numRows, false); - if(!order.IsValidPat(ord)) + if(!reserveLoopStates || !order.IsValidPat(ord)) continue; const ROWINDEX startRow = std::min(static_cast<ROWINDEX>(reset ? 0 : visitedRows.size()), numRows); |