Extract toArray()

Before: 9894, 8796, 9708, 12674, 9970
After:  9884, 8796, 9702, 12668, 9964
Target: 9800, 8458, 9634, 12290, 9702
This commit is contained in:
Benoit Blanchon
2025-09-17 21:07:35 +02:00
parent a9461f8e4d
commit f72526c093
3 changed files with 9 additions and 3 deletions

View File

@@ -71,7 +71,7 @@ class JsonDeserializer {
switch (current()) {
case '[':
if (filter.allowArray())
return parseArray(VariantImpl(variant, resources_).toArray(), filter,
return parseArray(VariantImpl::toArray(variant, resources_), filter,
nestingLimit);
else
return skipArray(nestingLimit);

View File

@@ -352,7 +352,7 @@ class MsgPackDeserializer {
ArrayImpl array;
if (allowArray) {
ARDUINOJSON_ASSERT(variant != 0);
array = VariantImpl(variant, resources_).toArray();
array = VariantImpl::toArray(variant, resources_);
}
TFilter elementFilter = filter[0U];

View File

@@ -478,9 +478,15 @@ class VariantImpl {
}
ArrayImpl toArray() {
ARDUINOJSON_ASSERT(type() == VariantType::Null); // must call clear() first
if (!data_)
return ArrayImpl();
return toArray(data_, resources_);
}
static ArrayImpl toArray(VariantData* data_, ResourceManager* resources_) {
ARDUINOJSON_ASSERT(data_ != nullptr);
ARDUINOJSON_ASSERT(data_->type == VariantType::Null);
ARDUINOJSON_ASSERT(resources_ != nullptr);
data_->type = VariantType::Array;
return ArrayImpl(new (&data_->content.asCollection) CollectionData(),
resources_);