GenericValue: round up during capacity growth
Suggested-by: @miloyip
This commit is contained in:
parent
f4f432801a
commit
0d2761a59c
@ -885,7 +885,7 @@ public:
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SizeType oldCapacity = o.capacity;
|
SizeType oldCapacity = o.capacity;
|
||||||
o.capacity += (oldCapacity >> 1); // grow by factor 1.5
|
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)));
|
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) {
|
GenericValue& PushBack(GenericValue& value, Allocator& allocator) {
|
||||||
RAPIDJSON_ASSERT(IsArray());
|
RAPIDJSON_ASSERT(IsArray());
|
||||||
if (data_.a.size >= data_.a.capacity)
|
if (data_.a.size >= data_.a.capacity)
|
||||||
Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity >> 1)), allocator);
|
Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : (data_.a.capacity + (data_.a.capacity + 1) / 2), allocator);
|
||||||
data_.a.elements[data_.a.size++].RawAssign(value);
|
data_.a.elements[data_.a.size++].RawAssign(value);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user