Skip to content

Commit

Permalink
refactor: Clean up and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jshearer committed Aug 4, 2023
1 parent 6fcbb9c commit 7ba0c0f
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions crates/doc/src/reduce/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,32 +339,22 @@ impl Strategy {
let left = shape_from_node(lhs).map_err(|e| Error::with_location(e, loc))?;
let right = shape_from_node(rhs).map_err(|e| Error::with_location(e, loc))?;

let merged = Shape::union(left, right);

let builder = SchemaBuilder::new(merged);
let root_schema = builder.root_schema();

let val = serde_json::to_value(root_schema).map_err(|e| {
Error::with_location(
Error::JsonSchemaMergeWrongType {
detail: Some(e.to_string()),
},
loc,
)
})?;

let node = HeapNode::from_serde(val, alloc).map_err(|e| {
Error::with_location(
Error::JsonSchemaMergeWrongType {
detail: Some(e.to_string()),
},
loc,
)
})?;
// Union together the LHS and RHS, and convert back from `Shape` into `HeapNode`.
let merged_doc = Shape::union(left, right)
.to_serde()
.and_then(|value| HeapNode::from_serde(value, alloc))
.map_err(|e| {
Error::with_location(
Error::JsonSchemaMergeWrongType {
detail: Some(e.to_string()),
},
loc,
)
})?;

*tape = &tape[rhs_tape_len..];

Ok(node)
Ok(merged_doc)
}

fn merge<'alloc, L: AsNode, R: AsNode>(
Expand Down

0 comments on commit 7ba0c0f

Please sign in to comment.