Added BasicJsonDocument::shrinkToFit()

This commit is contained in:
Benoit Blanchon
2019-11-07 15:40:20 +01:00
parent 1b8107094f
commit 062c1c13b5
13 changed files with 270 additions and 19 deletions

View File

@@ -103,7 +103,7 @@ class VariantData {
bool equals(const VariantData &other) const {
// Check that variant have the same type, but ignore string ownership
if ((type() | OWNERSHIP_BIT) != (other.type() | OWNERSHIP_BIT))
if ((type() | VALUE_IS_OWNED) != (other.type() | VALUE_IS_OWNED))
return false;
switch (type()) {
@@ -352,6 +352,12 @@ class VariantData {
return _content.asCollection.add(key, pool);
}
void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
if (_flags & VALUE_IS_OWNED) _content.asString += stringDistance;
if (_flags & COLLECTION_MASK)
_content.asCollection.movePointers(stringDistance, variantDistance);
}
private:
uint8_t type() const {
return _flags & VALUE_MASK;