From 264244d6a38d23ea573a3b24fb2da39b10cfd5ba Mon Sep 17 00:00:00 2001 From: sukibaby <163092272+sukibaby@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:36:12 -0700 Subject: [PATCH] Copy & swap assignment operator --- src/RageSoundPosMap.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/RageSoundPosMap.cpp b/src/RageSoundPosMap.cpp index 97746eca08..bc11207a77 100644 --- a/src/RageSoundPosMap.cpp +++ b/src/RageSoundPosMap.cpp @@ -9,11 +9,11 @@ #include #include -/* The number of frames we should keep pos_map data for. -This comes out to about ~800kb in audio frames, assuming 44.1khz. -File bitrate, metadata, etc will factor in here. If the queue is -TOO big it will make things slow, but 200k frames is no problem. -Making the queue larger than 200k hasn't been tested yet. */ +// The number of frames we should keep pos_map data for. +// This comes out to about ~800kb in audio frames, assuming 44.1khz. +// File bitrate, metadata, etc will factor in here. If the queue is +// TOO big it will make things slow, but 200k frames is no problem. +// Making the queue larger than 200k hasn't been tested extensively. const int pos_map_backlog_frames = 200000; struct pos_map_t @@ -50,9 +50,11 @@ pos_map_queue::pos_map_queue( const pos_map_queue &cpy ) pos_map_queue &pos_map_queue::operator=( const pos_map_queue &rhs ) { - if (this != &rhs){ - delete m_pImpl; - m_pImpl = new pos_map_impl( *rhs.m_pImpl ); + if (this != &rhs) + { + pos_map_impl* tempImpl = new pos_map_impl(*rhs.m_pImpl); + std::swap(m_pImpl, tempImpl); + delete tempImpl; } return *this; }