From b4e09414733f86504ee0e331aa7f39ecd28f83d6 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Fri, 11 Jun 2021 18:18:13 +0200 Subject: [PATCH] Don't cache reconstructed VST3 events at all There's no need to since reconstructing the event is very cheap, and this should be faster (less memory used) and also less error prone anyways. --- src/common/serialization/vst3/event-list.cpp | 19 ++++--------------- src/common/serialization/vst3/event-list.h | 11 ----------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/common/serialization/vst3/event-list.cpp b/src/common/serialization/vst3/event-list.cpp index 34b1ef50..40669c57 100644 --- a/src/common/serialization/vst3/event-list.cpp +++ b/src/common/serialization/vst3/event-list.cpp @@ -227,21 +227,10 @@ tresult PLUGIN_API YaEventList::getEvent(int32 index, return Steinberg::kInvalidArgument; } - // On the first call to this, we'll reconstruct `Event` objects out of our - // `YaEvent`s all at once. This is also done if for whatever reason the - // plugin `getEvent()`s an event it just added. - const size_t num_already_reconstructed_events = reconstructed_events.size(); - if (index >= static_cast(num_already_reconstructed_events)) { - reconstructed_events.resize(events.size()); - std::transform( - events.begin() + static_cast(num_already_reconstructed_events), - events.end(), - reconstructed_events.begin() + - static_cast(num_already_reconstructed_events), - [](const YaEvent& event) { return event.get(); }); - } - - e = reconstructed_events[index]; + // Reconstructing an event is cheap, but some events may contain pointers to + // heap data stored within the `events` vector so this event will still have + // the same lifetime as this class + e = events[index].get(); return Steinberg::kResultOk; } diff --git a/src/common/serialization/vst3/event-list.h b/src/common/serialization/vst3/event-list.h index a1c04dde..02a9c97b 100644 --- a/src/common/serialization/vst3/event-list.h +++ b/src/common/serialization/vst3/event-list.h @@ -257,21 +257,10 @@ class YaEventList : public Steinberg::Vst::IEventList { template void serialize(S& s) { s.container(events, 1 << 16); - - // NOTE: After deserializing events, we need to make sure to clear our - // caches since those may still contain old events - reconstructed_events.clear(); } private: boost::container::small_vector events; - - /** - * On the first `getEvent()` call we'll reconstruct these from `events` all - * at once. These event objects may not outlive this event list. - */ - boost::container::small_vector - reconstructed_events; }; #pragma GCC diagnostic pop