Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing make_static #1515

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions include/glaze/json/escape_unicode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,16 @@ namespace glz
{
template <string_literal Str>
inline constexpr auto escape_unicode = []() constexpr -> std::string_view {
constexpr auto escaped = []() constexpr {
static constexpr auto escaped = []() constexpr {
constexpr auto output_length = detail::escaped_length(Str.sv());
std::array<char, output_length + 1> result{}; // + 1 for null character
std::array<char, output_length + 1> result; // + 1 for null character
const auto escaped = detail::escape_json_string(Str.sv(), output_length);
for (size_t i = 0; i < output_length; ++i) {
result[i] = escaped[i];
}
result[output_length] = '\0';
return result;
}();

// make_static here required for GCC 12, in the future just make escaped static
auto& arr = detail::make_static<escaped>::value;
return {arr.data(), arr.size() - 1};
return {escaped.data(), escaped.size() - 1};
}();
}
14 changes: 4 additions & 10 deletions include/glaze/util/string_literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,21 @@ namespace glz

namespace detail
{
template <std::array V>
struct make_static
{
static constexpr auto value = V;
};

template <const std::string_view&... Strs>
inline constexpr std::string_view join()
{
constexpr auto joined_arr = []() {
// make a null terminated string_view
static constexpr auto joined_arr = []() {
constexpr size_t len = (Strs.size() + ... + 0);
std::array<char, len + 1> arr{};
std::array<char, len + 1> arr;
auto append = [i = 0, &arr](const auto& s) mutable {
for (auto c : s) arr[i++] = c;
};
(append(Strs), ...);
arr[len] = 0;
return arr;
}();
auto& static_arr = make_static<joined_arr>::value;
return {static_arr.data(), static_arr.size() - 1};
return {joined_arr.data(), joined_arr.size() - 1};
}
}

Expand Down
Loading