diff --git a/src/Magnum/DebugTools/FrameProfiler.cpp b/src/Magnum/DebugTools/FrameProfiler.cpp index 4226d60e8..76a2fa538 100644 --- a/src/Magnum/DebugTools/FrameProfiler.cpp +++ b/src/Magnum/DebugTools/FrameProfiler.cpp @@ -714,17 +714,15 @@ DebugTools::FrameProfilerGL::Value ConfigurationValue::toString(const DebugTools::FrameProfilerGL::Values value, ConfigurationValueFlags) { Containers::String out; + /* Create an array of strings where each is non-empty only if given bit is + set and then join them together to have just one allocation */ + const char* names[Containers::arraySize(DebugTools::FrameProfilerGLValueNames)]{}; for(std::size_t i = 0; i != Containers::arraySize(DebugTools::FrameProfilerGLValueNames); ++i) { - const auto bit = DebugTools::FrameProfilerGL::Value(1 << i); - if(value & bit) { - /** @todo ugh, one allocation per bit, fix when growable String is - a thing ... or maybe some "get set bits" utility and then call - join just once? */ - out = " "_s.joinWithoutEmptyParts({out, DebugTools::FrameProfilerGLValueNames[i]}); - } + if(value & DebugTools::FrameProfilerGL::Value(1 << i)) + names[i] = DebugTools::FrameProfilerGLValueNames[i]; } - return out; + return " "_s.joinWithoutEmptyParts(names); } DebugTools::FrameProfilerGL::Values ConfigurationValue::fromString(const Containers::StringView value, ConfigurationValueFlags) {