minor optimize

Signed-off-by: luofucong <luofc@foxmail.com>
This commit is contained in:
luofucong
2026-07-03 15:35:39 +08:00
parent 150e78f7e5
commit fef584f42e
2 changed files with 3 additions and 12 deletions

View File

@@ -427,8 +427,7 @@ impl JsonValue {
/// - `Null` aligns to any type, and any value aligns to `Null` as `Null`.
/// - Numbers are converted only within compatible number categories.
/// - Arrays align each element recursively to the expected item type.
/// - Objects require `expected` to contain all fields from the current value. Missing expected
/// fields are filled with `Null`.
/// - Objects require `expected` to have all fields from the current value.
/// - `Variant` preserves the original JSON payload as serialized bytes.
///
/// Returns an error if the value cannot be aligned without losing existing object fields or
@@ -467,7 +466,6 @@ impl JsonValue {
.collect::<Result<_>>()?,
),
(JsonVariant::Object(kvs), _) if kvs.is_empty() => JsonVariant::Null,
(JsonVariant::Object(mut kvs), JsonNativeType::Object(expected)) => {
ensure!(
expected.keys().len() >= kvs.keys().len()
@@ -481,15 +479,12 @@ impl JsonValue {
}
);
let mut object = BTreeMap::new();
for (field, field_type) in expected {
if let Some((k, v)) = kvs.remove_entry(field) {
object.insert(k, helper(v, field_type)?);
} else {
object.insert(field.clone(), JsonVariant::Null);
kvs.insert(k, helper(v, field_type)?);
}
}
JsonVariant::Object(object)
JsonVariant::Object(kvs)
}
(v, JsonNativeType::Variant) => {

View File

@@ -62,10 +62,6 @@ impl JsonVectorBuilder {
continue;
}
value.try_align(&self.merged_type)?;
if value.is_null() {
builder.push_null();
continue;
}
let value_ref = json_variant_to_struct_value_ref(value.variant(), struct_type.clone())?;
builder.push_struct_value_ref(value_ref)?;
}