From 0c5bbfa62db246b4c9e3b4a830782cf00a6847e2 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 8 Dec 2023 17:18:41 +0100 Subject: [PATCH] Location: add API to use cached sorted location list Every call to ::next_section() copies the location list and sorts all the regions. If the session has a significant amount of Locations and Section Marker (#9568 has 300+) sorting them each time when iterating over sections is significant. --- libs/ardour/ardour/location.h | 1 + libs/ardour/location.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libs/ardour/ardour/location.h b/libs/ardour/ardour/location.h index 8889ca39af..9a1d497567 100644 --- a/libs/ardour/ardour/location.h +++ b/libs/ardour/ardour/location.h @@ -301,6 +301,7 @@ public: timepos_t first_mark_after (timepos_t const &, bool include_special_ranges = false); Location* next_section (Location*, timepos_t&, timepos_t&) const; + Location* next_section_iter (Location*, timepos_t&, timepos_t&, std::vector& cache) const; Location* section_at (timepos_t const&, timepos_t&, timepos_t&) const; void marks_either_side (timepos_t const &, timepos_t &, timepos_t &) const; diff --git a/libs/ardour/location.cc b/libs/ardour/location.cc index d0cb25800d..c10fc816a0 100644 --- a/libs/ardour/location.cc +++ b/libs/ardour/location.cc @@ -1597,8 +1597,18 @@ Locations::sorted_section_locations (vector& locs) const Location* Locations::next_section (Location* l, timepos_t& start, timepos_t& end) const { - vector locs; - sorted_section_locations (locs); + std::vector locs; + return next_section_iter (l, start, end, locs); +} + +Location* +Locations::next_section_iter (Location* l, timepos_t& start, timepos_t& end, vector& locs) const +{ + if (!l) { + /* build cache */ + locs.clear (); + sorted_section_locations (locs); + } if (locs.size () < 2) { return NULL;