diff options
author | Milo Yip <miloyip@gmail.com> | 2014-09-02 18:11:34 +0400 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2014-09-02 18:11:34 +0400 |
commit | c6e6bca22f7e42f47479038053df03bd8d64f62d (patch) | |
tree | 33de35d817d94fdbd724ddc3670c28ad1ba59e6a | |
parent | 9289f3270d6f412b2a3b662693cc004d1e40526b (diff) | |
parent | 0d2761a59c48cd5694db7e53d3a092e97f028b09 (diff) |
Merge pull request #130 from pah/fixes/capacity-growth
GenericValue: reduce growth factor for array/object reallocations
-rw-r--r-- | include/rapidjson/document.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index 9c3d9acc..35d9f7f9 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -885,7 +885,7 @@ public: }
else {
SizeType oldCapacity = o.capacity;
- o.capacity *= 2;
+ o.capacity += (oldCapacity + 1) / 2; // grow by factor 1.5
o.members = reinterpret_cast<Member*>(allocator.Realloc(o.members, oldCapacity * sizeof(Member), o.capacity * sizeof(Member)));
}
}
@@ -1130,7 +1130,7 @@ int z = a[0u].GetInt(); // This works too. GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
RAPIDJSON_ASSERT(IsArray());
if (data_.a.size >= data_.a.capacity)
- Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : data_.a.capacity * 2, allocator);
+ Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
data_.a.elements[data_.a.size++].RawAssign(value);
return *this;
}
|