From daf0c78232d1a5b6c1afbbafcfd555c942ea51d1 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Sat, 15 Apr 2023 16:28:35 -0400 Subject: [PATCH] src: replace static const string_view by static constexpr PR-URL: https://github.com/nodejs/node/pull/47524 Reviewed-By: Yagiz Nizipli Reviewed-By: James M Snell --- src/json_utils.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/json_utils.cc b/src/json_utils.cc index f387985bccd761..2f24f304478162 100644 --- a/src/json_utils.cc +++ b/src/json_utils.cc @@ -3,7 +3,10 @@ namespace node { std::string EscapeJsonChars(std::string_view str) { - static const std::string_view control_symbols[0x20] = { + // 'static constexpr' is slightly better than static const + // since the initialization occurs at compile time. + // See https://lemire.me/blog/I3Cah + static constexpr std::string_view control_symbols[0x20] = { "\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", "\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\u000b", "\\f", "\\r", "\\u000e", "\\u000f", "\\u0010", "\\u0011",