From 5f1fd752faab0dc35077bc2936b7f5eea4e3a579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 18 Jun 2020 13:21:34 +0200 Subject: [PATCH] GL: no need to have those in a std::vector. Allocations are bad. Needless allocations are worse. Needless allocations forced on library load are the worst. --- src/Magnum/GL/Implementation/driverSpecific.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Magnum/GL/Implementation/driverSpecific.cpp b/src/Magnum/GL/Implementation/driverSpecific.cpp index 77259c8cc..1426b27cd 100644 --- a/src/Magnum/GL/Implementation/driverSpecific.cpp +++ b/src/Magnum/GL/Implementation/driverSpecific.cpp @@ -23,6 +23,7 @@ DEALINGS IN THE SOFTWARE. */ +#include #include #include #include @@ -35,8 +36,9 @@ namespace Magnum { namespace GL { namespace { - /* Search the code for the following strings to see where they are implemented. */ - std::vector KnownWorkarounds{ + +/* Search the code for the following strings to see where they are implemented. */ +const char* KnownWorkarounds[]{ /* [workarounds] */ #if defined(CORRADE_TARGET_APPLE) && !defined(CORRADE_TARGET_IOS) /* Calling glBufferData(), glMapBuffer(), glMapBufferRange() or glUnmapBuffer() @@ -368,7 +370,8 @@ namespace { "firefox-fake-disjoint-timer-query-webgl2", #endif /* [workarounds] */ - }; +}; + } namespace Implementation { @@ -471,7 +474,7 @@ auto Context::detectedDriver() -> DetectedDrivers { void Context::disableDriverWorkaround(const std::string& workaround) { /* Ignore unknown workarounds */ - if(std::find(KnownWorkarounds.begin(), KnownWorkarounds.end(), workaround) == KnownWorkarounds.end()) { + if(std::find(std::begin(KnownWorkarounds), std::end(KnownWorkarounds), workaround) == std::end(KnownWorkarounds)) { Warning() << "Unknown workaround" << workaround; return; } @@ -479,7 +482,9 @@ void Context::disableDriverWorkaround(const std::string& workaround) { } bool Context::isDriverWorkaroundDisabled(const char* workaround) { - CORRADE_INTERNAL_ASSERT(std::find(KnownWorkarounds.begin(), KnownWorkarounds.end(), workaround) != KnownWorkarounds.end()); + CORRADE_INTERNAL_ASSERT(std::find_if(std::begin(KnownWorkarounds), std::end(KnownWorkarounds), [&](const char* a) { + return std::strcmp(a, workaround) == 0; + }) != std::end(KnownWorkarounds)); /* If the workaround was already asked for or disabled, return its state, otherwise add it to the list as used one */