From 5f4ffed90bb4f0eed9731d020daa35fb2e34d0f2 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 31 May 2021 18:07:19 +0200 Subject: [PATCH] Prevent allocations in Vst3Logger::log_query_interface String constants will be converted to `std::string` because it's not constexpr yet, and that will allocate for longer strings. Since this function only prints something when `YABRIDGE_DEBUG_LEVEL` is set to 2 or higher that seems like a waste. --- CHANGELOG.md | 4 ++-- src/common/logging/vst3.cpp | 2 +- src/common/logging/vst3.h | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45fbde18..1717ec3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,8 +82,8 @@ Versioning](https://semver.org/spec/v2.0.0.html). - Fixed the _PG-8X_ VST2 plugin freezing in **REAPER** when loading the plugin. - Fixed _Voxengo_ VST2 plugins in **Renoise** freezing when loading a project or when otherwise restoring plugin state. -- Fixed logging traces in the VST2 audio processing functions causing - allocations even when `YABRIDGE_DEBUG_LEVEL` is not set to 2. +- Fixed logging traces in the VST2 audio processing functions and VST3 query + interfaces causing allocations even when `YABRIDGE_DEBUG_LEVEL` is not set to 2. - Fixed builds on Wine 6.8 because of internal changes to Wine's `windows.h` implementation. diff --git a/src/common/logging/vst3.cpp b/src/common/logging/vst3.cpp index d48c80ab..5dfc079b 100644 --- a/src/common/logging/vst3.cpp +++ b/src/common/logging/vst3.cpp @@ -54,7 +54,7 @@ std::string format_bstream(const YaBStream& stream) { Vst3Logger::Vst3Logger(Logger& generic_logger) : logger(generic_logger) {} void Vst3Logger::log_query_interface( - const std::string& where, + const char* where, tresult result, const std::optional& uid) { if (logger.verbosity >= Logger::Verbosity::all_events) [[unlikely]] { diff --git a/src/common/logging/vst3.h b/src/common/logging/vst3.h index b440fd9f..7e298226 100644 --- a/src/common/logging/vst3.h +++ b/src/common/logging/vst3.h @@ -18,6 +18,8 @@ #include +#include + #include "../serialization/vst3.h" #include "common.h" @@ -41,8 +43,14 @@ class Vst3Logger { * and queries for interfaces we do not implement depending on the verbosity * level. In case we could not get a FUID (because of null pointers, for * instance), `std::nullopt` should be passed. + * + * NOTE: We're passing a `const char*` here instead of a `const + * std::string&` because that will still allocate for longer strings + * because `std::string` isn't constexpr yet. Most calls to this + * function won't print anything, so we should make sure that calling + * it doesn't add unnecessary overhead. */ - void log_query_interface(const std::string& where, + void log_query_interface(const char* where, tresult result, const std::optional& uid);