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

Simplifying JSON read code #1449

Merged
merged 8 commits into from
Nov 22, 2024
Merged

Simplifying JSON read code #1449

merged 8 commits into from
Nov 22, 2024

Conversation

stephenberry
Copy link
Owner

@stephenberry stephenberry commented Nov 22, 2024

Breaking change for escaped unicode keys

Removed the option escaped_unicode_key_conversion, as it added significant complexity to the underlying code and required inefficient parsing due to heap allocations and resulted in inefficient hashing. Removing this option does not break any JSON conformance.

If you require both unescaped and escaped versions for a key, then register both of these keys with the same member pointer within glz::meta. This gives far better performance, but should still generally be avoided.

Added "glaze/json/escape_unicode.hpp", which provides glz::escape_unicode. This results in a compile time escaped version of the input string.

An example:

template <>
struct glz::meta<unicode_escaped_t>
{
   using T = unicode_escaped_t;
   static constexpr auto value = object("😀", &T::smile, escape_unicode<"😀">, &T::smile);
};

@@ -30,7 +30,11 @@ namespace glz
constexpr string_literal& operator=(const string_literal&) noexcept = default;
constexpr string_literal& operator=(string_literal&&) noexcept = default;

constexpr string_literal(const char (&str)[N]) noexcept { std::copy_n(str, N, value); }
constexpr string_literal(const char (&str)[N]) noexcept {
for (size_t i = 0; i < N; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to avoid include of <algorithm> ?

Copy link
Owner Author

@stephenberry stephenberry Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjanel, yes I'm slowly trying to remove large header includes where they aren't really necessary.

@stephenberry stephenberry changed the title Simplifying JSON code Simplifying JSON read code Nov 22, 2024
@stephenberry stephenberry merged commit 04b70c2 into main Nov 22, 2024
13 checks passed
@stephenberry stephenberry deleted the develop branch November 22, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants