| 936 | } |
| 937 | |
| 938 | void MutableGraphView::AddNewNodes( |
| 939 | absl::flat_hash_map<string, NodeViewFanouts>* renamed_fanouts, |
| 940 | std::vector<int>* new_node_indices) { |
| 941 | new_node_indices->reserve(mutation_.new_nodes_.size()); |
| 942 | for (auto& new_node : mutation_.new_nodes_) { |
| 943 | int node_index; |
| 944 | auto graph_it = node_index_by_name_.find(new_node.node.name()); |
| 945 | if (graph_it != node_index_by_name_.end()) { |
| 946 | // Overwrite existing node. |
| 947 | node_index = graph_it->second; |
| 948 | MutableNodeView& node_view = nodes_[node_index]; |
| 949 | RemoveAllFaninFanoutInternal(&node_view); |
| 950 | auto* node_def = graph_->mutable_node(node_index); |
| 951 | node_def->mutable_op()->swap(*new_node.node.mutable_op()); |
| 952 | node_def->mutable_device()->swap(*new_node.node.mutable_device()); |
| 953 | node_def->mutable_input()->Clear(); |
| 954 | node_def->mutable_attr()->swap(*new_node.node.mutable_attr()); |
| 955 | mutation_.removed_nodes_[node_index] = false; |
| 956 | } else { |
| 957 | // New node. |
| 958 | auto* new_node_def = graph_->add_node(); |
| 959 | *new_node_def = std::move(new_node.node); |
| 960 | node_index = nodes_.size(); |
| 961 | nodes_.emplace_back(this, node_index); |
| 962 | MutableNodeView& new_node_view = nodes_.back(); |
| 963 | auto it = renamed_fanouts->find(new_node_view.GetName()); |
| 964 | if (it != renamed_fanouts->end()) { |
| 965 | // Reuse fanouts of renamed node. |
| 966 | NodeViewFanouts& fanouts = it->second; |
| 967 | ReplaceNodeFanouts(&new_node_view, &fanouts); |
| 968 | renamed_fanouts->erase(it); |
| 969 | } |
| 970 | node_index_by_name_.emplace(new_node_view.GetName(), node_index); |
| 971 | } |
| 972 | new_node_indices->emplace_back(node_index); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | void MutableGraphView::FixRenamedFanouts( |
| 977 | const absl::flat_hash_map<string, NodeViewFanouts>& renamed_fanouts) { |
nothing calls this directly
no test coverage detected