From 9aad7b5727377a65b75c8c8c0afa4a5f3e483eed Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 22 Sep 2008 17:47:21 +0000 Subject: [PATCH] Speed up MIDI import (and non-cached cases of ControlList::eval) by a factor of roughly eleventy billion. git-svn-id: svn://localhost/ardour2/branches/3.0@3790 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/evoral/src/ControlList.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/evoral/src/ControlList.cpp b/libs/evoral/src/ControlList.cpp index b84586ab73..2ff5959afc 100644 --- a/libs/evoral/src/ControlList.cpp +++ b/libs/evoral/src/ControlList.cpp @@ -636,6 +636,8 @@ ControlList::truncate_end (double last_coordinate) beyond the new last coordinate. */ + // FIXME: SLOW! (size() == O(n)) + uint32_t sz = _events.size(); while (i != _events.rend() && sz > 2) { @@ -775,7 +777,10 @@ ControlList::unlocked_eval (double x) const double lval, uval; double fraction; - npoints = _events.size(); + const_iterator length_check_iter = _events.begin(); + for (npoints = 0; npoints < 4; ++npoints, ++length_check_iter) + if (length_check_iter == _events.end()) + break; switch (npoints) { case 0: @@ -1022,9 +1027,10 @@ ControlList::rt_safe_earliest_event_linear_unlocked (double start, double end, d { //cerr << "earliest_event(" << start << ", " << end << ", " << x << ", " << y << ", " << inclusive << endl; - if (_events.size() == 0) + const_iterator length_check_iter = _events.begin(); + if (_events.empty()) // 0 events return false; - else if (_events.size() == 1) + else if (_events.end() == ++length_check_iter) // 1 event return rt_safe_earliest_event_discrete_unlocked(start, end, x, y, inclusive); // Hack to avoid infinitely repeating the same event