Skip to content

Commit

Permalink
Merge 6c812e0 into 8f4c021
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-osmolsky committed Apr 23, 2020
2 parents 8f4c021 + 6c812e0 commit 77c15b8
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions include/rapidjson/document.h
Expand Up @@ -22,6 +22,8 @@
#include "internal/strfunc.h"
#include "memorystream.h"
#include "encodedstream.h"

#include <algorithm>
#include <new> // placement new
#include <limits>
#ifdef __cpp_lib_three_way_comparison
Expand Down Expand Up @@ -110,6 +112,9 @@ class GenericDocument;
template <typename Encoding, typename Allocator>
class GenericMember {
public:
// Allow default construction as it is needed during copying.
GenericMember() {}

GenericValue<Encoding, Allocator> name; //!< name of member (must be a string)
GenericValue<Encoding, Allocator> value; //!< value of member.

Expand Down Expand Up @@ -2113,9 +2118,11 @@ class GenericValue {
void SetArrayRaw(GenericValue* values, SizeType count, Allocator& allocator) {
data_.f.flags = kArrayFlag;
if (count) {
GenericValue* e = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
SetElementsPointer(e);
std::memcpy(static_cast<void*>(e), values, count * sizeof(GenericValue));
auto arr = static_cast<GenericValue*>(allocator.Malloc(count * sizeof(GenericValue)));
for (SizeType idx = 0; idx < count; ++idx)
new (arr + idx) GenericValue;
SetElementsPointer(arr);
std::copy_n(values, count, arr);
}
else
SetElementsPointer(0);
Expand All @@ -2126,9 +2133,11 @@ class GenericValue {
void SetObjectRaw(Member* members, SizeType count, Allocator& allocator) {
data_.f.flags = kObjectFlag;
if (count) {
Member* m = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
SetMembersPointer(m);
std::memcpy(static_cast<void*>(m), members, count * sizeof(Member));
auto arr = static_cast<Member*>(allocator.Malloc(count * sizeof(Member)));
for (SizeType idx = 0; idx < count; ++idx)
new (arr + idx) Member;
SetMembersPointer(arr);
std::copy_n(members, count, arr);
}
else
SetMembersPointer(0);
Expand Down

0 comments on commit 77c15b8

Please sign in to comment.