Browse Source

GL: no need to have those in a std::vector<std::string>.

Allocations are bad. Needless allocations are worse. Needless
allocations forced on library load are the worst.
pull/454/head
Vladimír Vondruš 6 years ago
parent
commit
5f1fd752fa
  1. 15
      src/Magnum/GL/Implementation/driverSpecific.cpp

15
src/Magnum/GL/Implementation/driverSpecific.cpp

@ -23,6 +23,7 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
#include <cstring>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
@ -35,8 +36,9 @@
namespace Magnum { namespace GL { namespace Magnum { namespace GL {
namespace { namespace {
/* Search the code for the following strings to see where they are implemented. */
std::vector<std::string> KnownWorkarounds{ /* Search the code for the following strings to see where they are implemented. */
const char* KnownWorkarounds[]{
/* [workarounds] */ /* [workarounds] */
#if defined(CORRADE_TARGET_APPLE) && !defined(CORRADE_TARGET_IOS) #if defined(CORRADE_TARGET_APPLE) && !defined(CORRADE_TARGET_IOS)
/* Calling glBufferData(), glMapBuffer(), glMapBufferRange() or glUnmapBuffer() /* Calling glBufferData(), glMapBuffer(), glMapBufferRange() or glUnmapBuffer()
@ -368,7 +370,8 @@ namespace {
"firefox-fake-disjoint-timer-query-webgl2", "firefox-fake-disjoint-timer-query-webgl2",
#endif #endif
/* [workarounds] */ /* [workarounds] */
}; };
} }
namespace Implementation { namespace Implementation {
@ -471,7 +474,7 @@ auto Context::detectedDriver() -> DetectedDrivers {
void Context::disableDriverWorkaround(const std::string& workaround) { void Context::disableDriverWorkaround(const std::string& workaround) {
/* Ignore unknown workarounds */ /* 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; Warning() << "Unknown workaround" << workaround;
return; return;
} }
@ -479,7 +482,9 @@ void Context::disableDriverWorkaround(const std::string& workaround) {
} }
bool Context::isDriverWorkaroundDisabled(const char* 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, /* If the workaround was already asked for or disabled, return its state,
otherwise add it to the list as used one */ otherwise add it to the list as used one */

Loading…
Cancel
Save