From ba123dfe878c8a37595a7855113fd0c91180209b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 6 Jan 2021 00:13:41 +0100 Subject: [PATCH] Cache playlist extents Calculating the extents iterates over all regions which can be expensive. Ardour's GUI calls this periodically to calculate session_gui_extents(). --- libs/ardour/ardour/playlist.h | 3 +++ libs/ardour/playlist.cc | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/playlist.h b/libs/ardour/ardour/playlist.h index 75ab8b4f2f..bdf9788875 100644 --- a/libs/ardour/ardour/playlist.h +++ b/libs/ardour/ardour/playlist.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -432,6 +433,8 @@ private: void coalesce_and_check_crossfades (std::list >); boost::shared_ptr find_regions_at (samplepos_t); + mutable boost::optional > _cached_extent; + samplepos_t _end_space; //this is used when we are pasting a range with extra space at the end bool _playlist_shift_active; }; diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index d9953e7e49..76676bd1cc 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -2238,6 +2238,8 @@ Playlist::find_next_region_boundary (samplepos_t sample, int dir) void Playlist::mark_session_dirty () { + _cached_extent.reset (); + if (!in_set_state && !holding_state ()) { _session.set_dirty(); } @@ -2464,8 +2466,13 @@ Playlist::all_regions_empty() const pair Playlist::get_extent () const { + if (_cached_extent) { + return _cached_extent.value (); + } + RegionReadLock rlock (const_cast(this)); - return _get_extent (); + _cached_extent = _get_extent (); + return _cached_extent.value (); } pair