From 0faaab452131158c7d3fe342f5cfc1822abbaf89 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 15 Jun 2009 15:04:55 +0200 Subject: [PATCH] PlayHandle: use QList instead of QVector for PlayHandle array Use QList instead of QVector when using a set of PlayHandle's. QList has faster insert/remove operations and in most cases we iterate through the array using iterators so there's no performance drop. Signed-off-by: Tobias Doerffel (cherry picked from commit 2cc49b80108ed14f5eadd64e90cad540afbb808d) --- include/mixer.h | 6 +++--- include/play_handle.h | 9 ++++----- src/core/mixer.cpp | 18 +++++++++--------- src/core/note_play_handle.cpp | 13 +++++++------ src/core/song.cpp | 6 +++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/mixer.h b/include/mixer.h index ae401f0f8..a615cac61 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -234,7 +234,7 @@ public: void removePlayHandle( playHandle * _ph ); - inline playHandleVector & playHandles( void ) + inline PlayHandleList & playHandles( void ) { return m_playHandles; } @@ -443,8 +443,8 @@ private: QWaitCondition m_queueReadyWaitCond; - playHandleVector m_playHandles; - constPlayHandleVector m_playHandlesToRemove; + PlayHandleList m_playHandles; + ConstPlayHandleList m_playHandlesToRemove; struct qualitySettings m_qualitySettings; float m_masterGain; diff --git a/include/play_handle.h b/include/play_handle.h index f6cee1bd7..27aa27573 100644 --- a/include/play_handle.h +++ b/include/play_handle.h @@ -1,8 +1,8 @@ /* * play_handle.h - base-class playHandle - core of rendering engine * - * Copyright (c) 2004-2008 Tobias Doerffel - * + * Copyright (c) 2004-2009 Tobias Doerffel + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -22,7 +22,6 @@ * */ - #ifndef _PLAY_HANDLE_H #define _PLAY_HANDLE_H @@ -98,8 +97,8 @@ private: } ; -typedef QVector playHandleVector; -typedef QVector constPlayHandleVector; +typedef QList PlayHandleList; +typedef QList ConstPlayHandleList; #endif diff --git a/src/core/mixer.cpp b/src/core/mixer.cpp index de8c1dc01..db0e0d9ed 100644 --- a/src/core/mixer.cpp +++ b/src/core/mixer.cpp @@ -248,7 +248,7 @@ void MixerWorkerThread::processJobQueue( void ) #define FILL_JOB_QUEUE_BEGIN(_vec_type,_vec,_condition) \ MixerWorkerThread::s_jobQueue.queueSize = 0; \ MixerWorkerThread::s_jobQueue.itemsDone = 0; \ - for( _vec_type::iterator it = _vec.begin(); \ + for( _vec_type::Iterator it = _vec.begin(); \ it != _vec.end(); ++it ) \ { \ if( _condition ) \ @@ -585,10 +585,10 @@ const surroundSampleFrame * mixer::renderNextBuffer( void ) // remove all play-handles that have to be deleted and delete // them if they still exist... // maybe this algorithm could be optimized... - constPlayHandleVector::iterator it_rem = m_playHandlesToRemove.begin(); + ConstPlayHandleList::Iterator it_rem = m_playHandlesToRemove.begin(); while( it_rem != m_playHandlesToRemove.end() ) { - playHandleVector::iterator it = qFind( m_playHandles.begin(), + PlayHandleList::Iterator it = qFind( m_playHandles.begin(), m_playHandles.end(), *it_rem ); if( it != m_playHandles.end() ) @@ -618,14 +618,14 @@ const surroundSampleFrame * mixer::renderNextBuffer( void ) // STAGE 1: run and render all play handles - FILL_JOB_QUEUE(playHandleVector,m_playHandles, + FILL_JOB_QUEUE(PlayHandleList,m_playHandles, MixerWorkerThread::PlayHandle, !( *it )->done()); START_JOBS(); WAIT_FOR_JOBS(); // removed all play handles which are done - for( playHandleVector::iterator it = m_playHandles.begin(); + for( PlayHandleList::Iterator it = m_playHandles.begin(); it != m_playHandles.end(); ) { if( ( *it )->affinityMatters() && @@ -689,7 +689,7 @@ void mixer::clear( void ) { // TODO: m_midiClient->noteOffAll(); lock(); - for( playHandleVector::iterator it = m_playHandles.begin(); + for( PlayHandleList::Iterator it = m_playHandles.begin(); it != m_playHandles.end(); ++it ) { // we must not delete instrument-play-handles as they exist @@ -903,7 +903,7 @@ void mixer::restoreAudioDevice( void ) void mixer::removeAudioPort( audioPort * _port ) { - QVector::iterator it = qFind( m_audioPorts.begin(), + QVector::Iterator it = qFind( m_audioPorts.begin(), m_audioPorts.end(), _port ); if( it != m_audioPorts.end() ) @@ -925,7 +925,7 @@ void mixer::removePlayHandle( playHandle * _ph ) if( _ph->affinityMatters() && _ph->affinity() == QThread::currentThread() ) { - playHandleVector::iterator it = + PlayHandleList::Iterator it = qFind( m_playHandles.begin(), m_playHandles.end(), _ph ); if( it != m_playHandles.end() ) @@ -947,7 +947,7 @@ void mixer::removePlayHandle( playHandle * _ph ) void mixer::removePlayHandles( track * _track ) { lock(); - playHandleVector::iterator it = m_playHandles.begin(); + PlayHandleList::Iterator it = m_playHandles.begin(); while( it != m_playHandles.end() ) { if( ( *it )->isFromTrack( _track ) ) diff --git a/src/core/note_play_handle.cpp b/src/core/note_play_handle.cpp index 0bacea6a0..320ae42a8 100644 --- a/src/core/note_play_handle.cpp +++ b/src/core/note_play_handle.cpp @@ -398,10 +398,11 @@ void notePlayHandle::mute( void ) int notePlayHandle::index( void ) const { - const playHandleVector & phv = engine::getMixer()->playHandles(); + const PlayHandleList & playHandles = + engine::getMixer()->playHandles(); int idx = 0; - for( constPlayHandleVector::ConstIterator it = phv.begin(); - it != phv.end(); ++it ) + for( PlayHandleList::ConstIterator it = playHandles.begin(); + it != playHandles.end(); ++it ) { const notePlayHandle * nph = dynamic_cast( *it ); @@ -426,11 +427,11 @@ int notePlayHandle::index( void ) const ConstNotePlayHandleList notePlayHandle::nphsOfInstrumentTrack( const instrumentTrack * _it, bool _all_ph ) { - const playHandleVector & phv = engine::getMixer()->playHandles(); + const PlayHandleList & playHandles = engine::getMixer()->playHandles(); ConstNotePlayHandleList cnphv; - for( constPlayHandleVector::ConstIterator it = phv.begin(); - it != phv.end(); ++it ) + for( PlayHandleList::ConstIterator it = playHandles.begin(); + it != playHandles.end(); ++it ) { const notePlayHandle * nph = dynamic_cast( *it ); diff --git a/src/core/song.cpp b/src/core/song.cpp index 3e9c307be..600391d6d 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -136,9 +136,9 @@ void song::setTempo( void ) { const bpm_t tempo = (bpm_t) m_tempoModel.value(); engine::getMixer()->lock(); - playHandleVector & phv = engine::getMixer()->playHandles(); - for( playHandleVector::iterator it = phv.begin(); it != phv.end(); - ++it ) + PlayHandleList & playHandles = engine::getMixer()->playHandles(); + for( PlayHandleList::Iterator it = playHandles.begin(); + it != playHandles.end(); ++it ) { notePlayHandle * nph = dynamic_cast( *it ); if( nph && !nph->released() )