diff --git a/src/catch2/internal/catch_jsonwriter.cpp b/src/catch2/internal/catch_jsonwriter.cpp index a33590f0..190a978c 100644 --- a/src/catch2/internal/catch_jsonwriter.cpp +++ b/src/catch2/internal/catch_jsonwriter.cpp @@ -16,9 +16,22 @@ namespace Catch { namespace { - static bool needsEscape( char c ) { - return c == '"' || c == '\\' || c == '\b' || c == '\f' || - c == '\n' || c == '\r' || c == '\t'; + struct EscapeLUT { + bool escape[256] = {}; + constexpr EscapeLUT() { + escape[static_cast( '"' )] = true; + escape[static_cast( '\\' )] = true; + escape[static_cast( '\b' )] = true; + escape[static_cast( '\f' )] = true; + escape[static_cast( '\n' )] = true; + escape[static_cast( '\r' )] = true; + escape[static_cast( '\t' )] = true; + } + }; + static constexpr EscapeLUT escapeLUT{}; + + static constexpr bool needsEscape( char c ) { + return escapeLUT.escape[static_cast( c )]; } static Catch::StringRef makeEscapeStringRef( char c ) {