From eac818d32fbdd8d03764b3a0da552b8a32e6683e Mon Sep 17 00:00:00 2001 From: "andrei.svatko" Date: Sat, 1 Jun 2024 10:44:56 +0300 Subject: [PATCH 1/4] double curly braces in a test --- test/corelib/src/detail/span_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/corelib/src/detail/span_tests.cpp b/test/corelib/src/detail/span_tests.cpp index 270ee574e..9f2a4ad29 100644 --- a/test/corelib/src/detail/span_tests.cpp +++ b/test/corelib/src/detail/span_tests.cpp @@ -23,7 +23,7 @@ TEST_CASE("jsoncons::detail::span constructor tests") SECTION("jsoncons::detail::span(C& c)") { using C = std::vector; - C c = {1,2,3,4}; + C c = {{1,2,3,4}}; jsoncons::detail::span s(c); CHECK(s.size() == c.size()); From 84abb20fe211a8f810d7e58b4009cc625b294f20 Mon Sep 17 00:00:00 2001 From: "andrei.svatko" Date: Sat, 1 Jun 2024 10:49:36 +0300 Subject: [PATCH 2/4] use c_str() in ctor --- include/jsoncons/json_object.hpp | 12 ++++++------ include/jsoncons_ext/cbor/cbor_parser.hpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/jsoncons/json_object.hpp b/include/jsoncons/json_object.hpp index 68431373e..da16bc93b 100644 --- a/include/jsoncons/json_object.hpp +++ b/include/jsoncons/json_object.hpp @@ -391,7 +391,7 @@ namespace jsoncons { members_.reserve(count); for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first,get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(),get_allocator()), s->second); } std::stable_sort(members_.begin(), members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); @@ -534,13 +534,13 @@ namespace jsoncons { auto last = first + count; std::sort(first, last, compare); - members_.emplace_back(key_type(first->name,get_allocator()), std::move(first->value)); + members_.emplace_back(key_type(first->name.c_str(),get_allocator()), std::move(first->value)); auto prev_it = first; for (auto it = first+1; it != last; ++it) { if (it->name != prev_it->name) { - members_.emplace_back(key_type(it->name,get_allocator()), std::move(it->value)); + members_.emplace_back(key_type(it->name.c_str(),get_allocator()), std::move(it->value)); } ++prev_it; } @@ -552,7 +552,7 @@ namespace jsoncons { { for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first,get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(),get_allocator()), s->second); } std::stable_sort(members_.begin(),members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); @@ -1340,10 +1340,10 @@ namespace jsoncons { std::unordered_set keys; for (auto it = first; it != last; ++it) { - key_type key{it->first, get_allocator()}; + key_type key{it->first.c_str(), get_allocator()}; if (keys.find(key) == keys.end()) { - keys.emplace(key, get_allocator()); + keys.emplace(key.c_str(), get_allocator()); members_.emplace_back(std::move(key), it->second); } } diff --git a/include/jsoncons_ext/cbor/cbor_parser.hpp b/include/jsoncons_ext/cbor/cbor_parser.hpp index bf3e6b64a..e48c5b788 100644 --- a/include/jsoncons_ext/cbor/cbor_parser.hpp +++ b/include/jsoncons_ext/cbor/cbor_parser.hpp @@ -63,7 +63,7 @@ class basic_cbor_parser : public ser_context byte_string_type bytes; mapped_string(const string_type& str, const allocator_type& alloc = allocator_type()) - : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str,alloc), bytes(alloc) + : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str.c_str(),alloc), bytes(alloc) { } From f2e403b681a1354c04d9f4a6d8e312db97e49643 Mon Sep 17 00:00:00 2001 From: "andrei.svatko" Date: Tue, 4 Jun 2024 17:35:22 +0300 Subject: [PATCH 3/4] used size() to avoid reallocations --- include/jsoncons/json_object.hpp | 12 ++++++------ include/jsoncons_ext/cbor/cbor_parser.hpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/jsoncons/json_object.hpp b/include/jsoncons/json_object.hpp index da16bc93b..665486b36 100644 --- a/include/jsoncons/json_object.hpp +++ b/include/jsoncons/json_object.hpp @@ -391,7 +391,7 @@ namespace jsoncons { members_.reserve(count); for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first.c_str(),get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(),s->first.size(),get_allocator()), s->second); } std::stable_sort(members_.begin(), members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); @@ -534,13 +534,13 @@ namespace jsoncons { auto last = first + count; std::sort(first, last, compare); - members_.emplace_back(key_type(first->name.c_str(),get_allocator()), std::move(first->value)); + members_.emplace_back(key_type(first->name.c_str(),first->name.size(),get_allocator()), std::move(first->value)); auto prev_it = first; for (auto it = first+1; it != last; ++it) { if (it->name != prev_it->name) { - members_.emplace_back(key_type(it->name.c_str(),get_allocator()), std::move(it->value)); + members_.emplace_back(key_type(it->name.c_str(),it->name.size(),get_allocator()), std::move(it->value)); } ++prev_it; } @@ -552,7 +552,7 @@ namespace jsoncons { { for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first.c_str(),get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(),s->first.size(),get_allocator()), s->second); } std::stable_sort(members_.begin(),members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); @@ -1340,10 +1340,10 @@ namespace jsoncons { std::unordered_set keys; for (auto it = first; it != last; ++it) { - key_type key{it->first.c_str(), get_allocator()}; + key_type key{it->first.c_str(), it->first.size(), get_allocator()}; if (keys.find(key) == keys.end()) { - keys.emplace(key.c_str(), get_allocator()); + keys.emplace(key.c_str(), key.size(), get_allocator()); members_.emplace_back(std::move(key), it->second); } } diff --git a/include/jsoncons_ext/cbor/cbor_parser.hpp b/include/jsoncons_ext/cbor/cbor_parser.hpp index e48c5b788..30092bfb8 100644 --- a/include/jsoncons_ext/cbor/cbor_parser.hpp +++ b/include/jsoncons_ext/cbor/cbor_parser.hpp @@ -63,7 +63,7 @@ class basic_cbor_parser : public ser_context byte_string_type bytes; mapped_string(const string_type& str, const allocator_type& alloc = allocator_type()) - : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str.c_str(),alloc), bytes(alloc) + : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str.c_str(),str.size(),alloc), bytes(alloc) { } From 6f0a77c8260508ccc7ec736c3a10f7f66a835cfc Mon Sep 17 00:00:00 2001 From: "andrei.svatko" Date: Tue, 4 Jun 2024 17:40:38 +0300 Subject: [PATCH 4/4] added some whitespaces --- include/jsoncons/json_object.hpp | 8 ++++---- include/jsoncons_ext/cbor/cbor_parser.hpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/jsoncons/json_object.hpp b/include/jsoncons/json_object.hpp index 665486b36..d5954cba4 100644 --- a/include/jsoncons/json_object.hpp +++ b/include/jsoncons/json_object.hpp @@ -391,7 +391,7 @@ namespace jsoncons { members_.reserve(count); for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first.c_str(),s->first.size(),get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(), s->first.size(), get_allocator()), s->second); } std::stable_sort(members_.begin(), members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); @@ -534,13 +534,13 @@ namespace jsoncons { auto last = first + count; std::sort(first, last, compare); - members_.emplace_back(key_type(first->name.c_str(),first->name.size(),get_allocator()), std::move(first->value)); + members_.emplace_back(key_type(first->name.c_str(), first->name.size(), get_allocator()), std::move(first->value)); auto prev_it = first; for (auto it = first+1; it != last; ++it) { if (it->name != prev_it->name) { - members_.emplace_back(key_type(it->name.c_str(),it->name.size(),get_allocator()), std::move(it->value)); + members_.emplace_back(key_type(it->name.c_str(), it->name.size(), get_allocator()), std::move(it->value)); } ++prev_it; } @@ -552,7 +552,7 @@ namespace jsoncons { { for (auto s = first; s != last; ++s) { - members_.emplace_back(key_type(s->first.c_str(),s->first.size(),get_allocator()), s->second); + members_.emplace_back(key_type(s->first.c_str(), s->first.size(), get_allocator()), s->second); } std::stable_sort(members_.begin(),members_.end(), [](const key_value_type& a, const key_value_type& b) -> bool {return a.key().compare(b.key()) < 0;}); diff --git a/include/jsoncons_ext/cbor/cbor_parser.hpp b/include/jsoncons_ext/cbor/cbor_parser.hpp index 30092bfb8..ab9fb6c9b 100644 --- a/include/jsoncons_ext/cbor/cbor_parser.hpp +++ b/include/jsoncons_ext/cbor/cbor_parser.hpp @@ -63,7 +63,7 @@ class basic_cbor_parser : public ser_context byte_string_type bytes; mapped_string(const string_type& str, const allocator_type& alloc = allocator_type()) - : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str.c_str(),str.size(),alloc), bytes(alloc) + : type(jsoncons::cbor::detail::cbor_major_type::text_string), str(str.c_str(), str.size(), alloc), bytes(alloc) { }