diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-09-03 10:31:13 +0200 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2024-09-03 16:06:20 +0200 |
commit | fac973647d69dd14089cee9972e8dfa0074c8a97 (patch) | |
tree | ee3ddee65e7fbbebb3e55ae213ac31f4a9d728b2 /cmake | |
parent | 9cb9651d92ddb5d92724f6a52440601c7a0bbcf8 (diff) |
test: Use string_view for json_tests
This avoids a static constructor of the global std::string, and rules
out possibly expensive and implicit copies of the string completely.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/script/GenerateHeaderFromJson.cmake | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cmake/script/GenerateHeaderFromJson.cmake b/cmake/script/GenerateHeaderFromJson.cmake index 279ceedf04..53d1165272 100644 --- a/cmake/script/GenerateHeaderFromJson.cmake +++ b/cmake/script/GenerateHeaderFromJson.cmake @@ -5,10 +5,10 @@ file(READ ${JSON_SOURCE_PATH} hex_content HEX) string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" bytes "${hex_content}") -file(WRITE ${HEADER_PATH} "#include <string>\n") +file(WRITE ${HEADER_PATH} "#include <string_view>\n") file(APPEND ${HEADER_PATH} "namespace json_tests{\n") get_filename_component(json_source_basename ${JSON_SOURCE_PATH} NAME_WE) -file(APPEND ${HEADER_PATH} "static const std::string ${json_source_basename}{\n") +file(APPEND ${HEADER_PATH} "inline constexpr char detail_${json_source_basename}_bytes[]{\n") set(i 0) foreach(byte ${bytes}) @@ -21,4 +21,6 @@ foreach(byte ${bytes}) endif() endforeach() -file(APPEND ${HEADER_PATH} "\n};};") +file(APPEND ${HEADER_PATH} "\n};\n") +file(APPEND ${HEADER_PATH} "inline constexpr std::string_view ${json_source_basename}{std::begin(detail_${json_source_basename}_bytes), std::end(detail_${json_source_basename}_bytes)};") +file(APPEND ${HEADER_PATH} "\n}") |