13
0

temporal: minor optimization for TempoMap::{tempo,meter}_at() to cover common case

This commit is contained in:
Paul Davis 2023-10-20 11:06:00 -06:00
parent 671e0b356b
commit 4228fce86b

View File

@ -871,6 +871,10 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
template<typename TimeType, typename Comparator> TempoPoint const & _tempo_at (TimeType when, Comparator cmp) const {
assert (!_tempos.empty());
if (_tempos.size() == 1) {
return _tempos.front();
}
Tempos::const_iterator prev = _tempos.end();
for (Tempos::const_iterator t = _tempos.begin(); t != _tempos.end(); ++t) {
if (cmp (*t, when)) {
@ -888,6 +892,10 @@ class /*LIBTEMPORAL_API*/ TempoMap : public PBD::StatefulDestructible
template<typename TimeType, typename Comparator> MeterPoint const & _meter_at (TimeType when, Comparator cmp) const {
assert (!_meters.empty());
if (_meters.size() == 1) {
return _meters.front();
}
Meters::const_iterator prev = _meters.end();
for (Meters::const_iterator m = _meters.begin(); m != _meters.end(); ++m) {
if (cmp (*m, when)) {