Skip to content

Commit 2c2b6d1

Browse files
lemireMoLow
authored andcommitted
src: replace static const string_view by static constexpr
PR-URL: nodejs#47524 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 3840bb5 commit 2c2b6d1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/json_utils.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace node {
44

55
std::string EscapeJsonChars(std::string_view str) {
6-
static const std::string_view control_symbols[0x20] = {
6+
// 'static constexpr' is slightly better than static const
7+
// since the initialization occurs at compile time.
8+
// See https://lemire.me/blog/I3Cah
9+
static constexpr std::string_view control_symbols[0x20] = {
710
"\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005",
811
"\\u0006", "\\u0007", "\\b", "\\t", "\\n", "\\u000b",
912
"\\f", "\\r", "\\u000e", "\\u000f", "\\u0010", "\\u0011",

0 commit comments

Comments
 (0)