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.
This commit is contained in:
Robin Gareus 2023-12-08 17:18:41 +01:00
parent ebc887e33d
commit 0c5bbfa62d
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
2 changed files with 13 additions and 2 deletions

View file

@ -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<LocationPair>& 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;

View file

@ -1597,8 +1597,18 @@ Locations::sorted_section_locations (vector<LocationPair>& locs) const
Location*
Locations::next_section (Location* l, timepos_t& start, timepos_t& end) const
{
vector<LocationPair> locs;
sorted_section_locations (locs);
std::vector<Locations::LocationPair> locs;
return next_section_iter (l, start, end, locs);
}
Location*
Locations::next_section_iter (Location* l, timepos_t& start, timepos_t& end, vector<LocationPair>& locs) const
{
if (!l) {
/* build cache */
locs.clear ();
sorted_section_locations (locs);
}
if (locs.size () < 2) {
return NULL;