Merge pull request #365 from mloskot/patch-1

Add missing allocator to uses of AddMember
This commit is contained in:
Milo Yip 2015-06-25 09:24:56 +08:00
commit c752b6aa68

View File

@ -292,12 +292,13 @@ The simple answer is performance. For fixed size JSON types (Number, True, False
For example, if normal *copy* semantics was used: For example, if normal *copy* semantics was used:
~~~~~~~~~~cpp ~~~~~~~~~~cpp
Document d;
Value o(kObjectType); Value o(kObjectType);
{ {
Value contacts(kArrayType); Value contacts(kArrayType);
// adding elements to contacts array. // adding elements to contacts array.
// ... // ...
o.AddMember("contacts", contacts); // deep clone contacts (may be with lots of allocations) o.AddMember("contacts", contacts, d.GetAllocator()); // deep clone contacts (may be with lots of allocations)
// destruct contacts. // destruct contacts.
} }
~~~~~~~~~~ ~~~~~~~~~~
@ -313,11 +314,12 @@ To make RapidJSON simple and fast, we chose to use *move* semantics for assignme
So, with move semantics, the above example becomes: So, with move semantics, the above example becomes:
~~~~~~~~~~cpp ~~~~~~~~~~cpp
Document d;
Value o(kObjectType); Value o(kObjectType);
{ {
Value contacts(kArrayType); Value contacts(kArrayType);
// adding elements to contacts array. // adding elements to contacts array.
o.AddMember("contacts", contacts); // just memcpy() of contacts itself to the value of new member (16 bytes) o.AddMember("contacts", contacts, d.GetAllocator()); // just memcpy() of contacts itself to the value of new member (16 bytes)
// contacts became Null here. Its destruction is trivial. // contacts became Null here. Its destruction is trivial.
} }
~~~~~~~~~~ ~~~~~~~~~~