| 188 | } |
| 189 | |
| 190 | fn add_node( |
| 191 | nodes: &mut HashMap<NodeId, NodeState>, |
| 192 | pending_grafts: &mut HashMap<TreeId, NodeId>, |
| 193 | changes: &mut Option<&mut InternalChanges>, |
| 194 | parent_and_index: Option<ParentAndIndex>, |
| 195 | id: NodeId, |
| 196 | data: NodeData, |
| 197 | ) { |
| 198 | if let Some(subtree_id) = data.tree_id() { |
| 199 | if !data.children().is_empty() { |
| 200 | panic!( |
| 201 | "Node {:?} has both tree_id and children. \ |
| 202 | A graft node's only child comes from its subtree.", |
| 203 | id.to_components().0 |
| 204 | ); |
| 205 | } |
| 206 | record_graft(pending_grafts, subtree_id, id); |
| 207 | } |
| 208 | let state = NodeState { |
| 209 | parent_and_index, |
| 210 | data, |
| 211 | }; |
| 212 | nodes.insert(id, state); |
| 213 | if let Some(changes) = changes { |
| 214 | changes.added_node_ids.insert(id); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | for (local_node_id, node_data) in update.nodes { |
| 219 | let node_id = map_id(local_node_id); |