Skip to content

Commit

Permalink
src: replace static const string_view by static constexpr
Browse files Browse the repository at this point in the history
PR-URL: #47524
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
lemire authored and targos committed May 2, 2023
1 parent 57e7ed7 commit daf0c78
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/json_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit daf0c78

Please sign in to comment.