# HG changeset patch # User Chris Cannam # Date 1552303517 0 # Node ID 7dbb2a7b592eb81c90b8094a1393af325d0f3eb7 # Parent dcd510bd89dbace1c69f15cc12fcdaddb9ad43f6 That last change didn't seem worthwhile diff -r dcd510bd89db -r 7dbb2a7b592e base/EventSeries.h --- a/base/EventSeries.h Mon Mar 11 11:17:30 2019 +0000 +++ b/base/EventSeries.h Mon Mar 11 11:25:17 2019 +0000 @@ -19,9 +19,6 @@ #include -#include -#include - //#define DEBUG_EVENT_SERIES 1 /** @@ -81,7 +78,7 @@ << endl; break; } - i.value().insert(p); + i->second.insert(p); } } @@ -103,7 +100,7 @@ if (pitr == m_events.end()) { return; // we don't know this event } else { - if (--(pitr.value()) == 0) { + if (--(pitr->second) == 0) { isUnique = true; m_events.erase(pitr); } @@ -135,7 +132,7 @@ throw std::logic_error("unexpectedly reached end of map"); } - i.value().remove(p); + i->second.erase(p); } // Tidy up by removing any entries that are now identical @@ -150,8 +147,8 @@ } for (auto i = i0; i != m_seams.end(); ++i) { - if (pitr != m_seams.end() && i.value() == pitr.value()) { - redundant.push_back(i.key()); + if (pitr != m_seams.end() && i->second == pitr->second) { + redundant.push_back(i->first); } pitr = i; if (i == i1) { @@ -160,7 +157,7 @@ } for (sv_frame_t f: redundant) { - m_seams.remove(f); + m_seams.erase(f); } } @@ -215,11 +212,11 @@ // first find any zero-duration events - auto pitr = m_events.lowerBound(Event(start, QString())); - while (pitr != m_events.end() && pitr.key().getFrame() < end) { - if (!pitr.key().hasDuration()) { - for (int i = 0; i < pitr.value(); ++i) { - span.push_back(pitr.key()); + auto pitr = m_events.lower_bound(Event(start, QString())); + while (pitr != m_events.end() && pitr->first.getFrame() < end) { + if (!pitr->first.hasDuration()) { + for (int i = 0; i < pitr->second; ++i) { + span.push_back(pitr->first); } } ++pitr; @@ -228,20 +225,20 @@ // now any non-zero-duration ones from the seam map std::set found; - auto sitr = m_seams.lowerBound(start); - if (sitr == m_seams.end() || sitr.key() > start) { + auto sitr = m_seams.lower_bound(start); + if (sitr == m_seams.end() || sitr->first > start) { if (sitr != m_seams.begin()) { --sitr; } } - while (sitr != m_seams.end() && sitr.key() < end) { - for (const auto &p: sitr.value()) { + while (sitr != m_seams.end() && sitr->first < end) { + for (const auto &p: sitr->second) { found.insert(p); } ++sitr; } for (const auto &p: found) { - int n = m_events.value(p); + int n = m_events.at(p); if (n < 1) { throw std::logic_error("event is in seams but not events"); } @@ -265,39 +262,33 @@ // first find any zero-duration events - auto pitr = m_events.lowerBound(Event(frame, QString())); - while (pitr != m_events.end() && pitr.key().getFrame() == frame) { - if (!pitr.key().hasDuration()) { - for (int i = 0; i < pitr.value(); ++i) { - cover.push_back(pitr.key()); + auto pitr = m_events.lower_bound(Event(frame, QString())); + while (pitr != m_events.end() && pitr->first.getFrame() == frame) { + if (!pitr->first.hasDuration()) { + for (int i = 0; i < pitr->second; ++i) { + cover.push_back(pitr->first); } } ++pitr; } - // now any non-zero-duration ones from the seam map. We insert - // these into a std::set to recover the ordering, lost by QSet + // now any non-zero-duration ones from the seam map - std::set found; - auto sitr = m_seams.lowerBound(frame); - if (sitr == m_seams.end() || sitr.key() > frame) { + auto sitr = m_seams.lower_bound(frame); + if (sitr == m_seams.end() || sitr->first > frame) { if (sitr != m_seams.begin()) { --sitr; } } - if (sitr != m_seams.end() && sitr.key() <= frame) { - for (const auto &p: sitr.value()) { - found.insert(p); - } - ++sitr; - } - for (const auto &p: found) { - int n = m_events.value(p); - if (n < 1) { - throw std::logic_error("event is in seams but not events"); - } - for (int i = 0; i < n; ++i) { - cover.push_back(p); + if (sitr != m_seams.end() && sitr->first <= frame) { + for (const auto &p: sitr->second) { + int n = m_events.at(p); + if (n < 1) { + throw std::logic_error("event is in seams but not events"); + } + for (int i = 0; i < n; ++i) { + cover.push_back(p); + } } } @@ -310,7 +301,7 @@ * m_events.size() if the series contains duplicate events. */ int m_count; - + /** * The (ordered) Events map acts as a list of all the events in * the series. For reasons of backward compatibility, we have to @@ -325,7 +316,7 @@ * different "key" in this map - we only add or delete them or * change their counts. */ - typedef QMap Events; + typedef std::map Events; Events m_events; /** @@ -340,7 +331,7 @@ * Only events with duration appear in this map; point events * appear only in m_events. */ - typedef QMap> FrameEventMap; + typedef std::map> FrameEventMap; FrameEventMap m_seams; /** Create a seam at the given frame, copying from the prior seam @@ -348,17 +339,17 @@ * leave it untouched. */ void createSeam(sv_frame_t frame) { - auto itr = m_seams.lowerBound(frame); - if (itr == m_seams.end() || itr.key() > frame) { + auto itr = m_seams.lower_bound(frame); + if (itr == m_seams.end() || itr->first > frame) { if (itr != m_seams.begin()) { --itr; } } if (itr == m_seams.end()) { m_seams[frame] = {}; - } else if (itr.key() < frame) { - m_seams[frame] = itr.value(); - } else if (itr.key() > frame) { // itr must be begin() + } else if (itr->first < frame) { + m_seams[frame] = itr->second; + } else if (itr->first > frame) { // itr must be begin() m_seams[frame] = {}; } } diff -r dcd510bd89db -r 7dbb2a7b592e base/test/StressEventSeries.h --- a/base/test/StressEventSeries.h Mon Mar 11 11:17:30 2019 +0000 +++ b/base/test/StressEventSeries.h Mon Mar 11 11:25:17 2019 +0000 @@ -72,7 +72,9 @@ void longish_4() { longish_n(10000); } void longish_5() { longish_n(100000); } - /* cf5196881e3e+ + /* + +cf5196881e3e: Time for 1000 short events = 1.169ms Time for 10000 short events = 20.566ms @@ -86,6 +88,23 @@ 13.40user 0.37system 0:13.84elapsed 99%CPU (0avgtext+0avgdata 1052000maxresident)k 0inputs+40outputs (0major+260249minor)pagefaults 0swaps + + +dcd510bd89db: + + Time for 1000 short events = 1.824ms + Time for 10000 short events = 19.203ms + Time for 100000 short events = 270.631ms + Time for 1000000 short events = 4425.2ms + Time for 1000 longish events = 2.395ms + Time for 10000 longish events = 83.623ms + Time for 100000 longish events = 5958.28ms + +Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 13116ms + +13.64user 0.26system 0:13.98elapsed 99%CPU (0avgtext+0avgdata 948104maxresident)k +0inputs+40outputs (0major+234387minor)pagefaults 0swaps + */ };