| 717 | } |
| 718 | |
| 719 | PathMatcher::NodePtr PathMatcher::removePathsWalk( Node *node, const Node *srcNode, bool shared, bool &removed ) |
| 720 | { |
| 721 | shared = shared || node->refCount() > 1; |
| 722 | NodePtr result; |
| 723 | |
| 724 | if( node->terminator && srcNode->terminator ) |
| 725 | { |
| 726 | writable( node, result, shared )->terminator = false; |
| 727 | removed = true; |
| 728 | } |
| 729 | |
| 730 | for( Node::ChildMap::const_iterator it = srcNode->children.begin(), eIt = srcNode->children.end(); it != eIt; ++it ) |
| 731 | { |
| 732 | const Node::ChildMapIterator childIt = node->children.find( it->first ); |
| 733 | if( childIt != node->children.end() ) |
| 734 | { |
| 735 | Node *child = childIt->second.get(); |
| 736 | NodePtr newChild = removePathsWalk( child, it->second.get(), shared, removed ); |
| 737 | |
| 738 | if( newChild && !newChild->isEmpty() ) |
| 739 | { |
| 740 | writable( node, result, shared )->children[childIt->first] = newChild; |
| 741 | } |
| 742 | else if( child->isEmpty() || ( newChild && newChild->isEmpty() ) ) |
| 743 | { |
| 744 | writable( node, result, shared )->children.erase( childIt->first ); |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | return result; |
| 750 | } |
| 751 | |
| 752 | namespace |
| 753 | { |