| 300 | } |
| 301 | |
| 302 | std::unique_ptr<PrefixMatch::Tables::Matcher> BuildMatcher( |
| 303 | const DictPtr& dict) { |
| 304 | const std::list<DictPtr>* dictGroupItems = dict->GetDictGroupItems(); |
| 305 | if (dictGroupItems != nullptr) { |
| 306 | // If the entire subtree is a pure union of leaf dicts, merge all entries |
| 307 | // into a single LeafMatcher. One trie traversal finds the longest match |
| 308 | // across all dicts, which equals union semantics, and eliminates the |
| 309 | // overhead of GroupMatcher dispatch and multiple traversals. |
| 310 | if (CanFlattenAsUnion(dict)) { |
| 311 | std::unique_ptr<LeafMatcher> leaf(new LeafMatcher); |
| 312 | CollectAllLeafDicts(dict, leaf.get()); |
| 313 | return std::move(leaf); |
| 314 | } |
| 315 | |
| 316 | std::unique_ptr<GroupMatcher> group( |
| 317 | new GroupMatcher(dict->GetMatchPolicy())); |
| 318 | for (const DictPtr& child : *dictGroupItems) { |
| 319 | group->AddChild(BuildMatcher(child)); |
| 320 | } |
| 321 | return std::move(group); |
| 322 | } |
| 323 | |
| 324 | std::unique_ptr<LeafMatcher> leaf(new LeafMatcher); |
| 325 | leaf->AddDict(dict); |
| 326 | return std::move(leaf); |
| 327 | } |
| 328 | |
| 329 | PrefixMatch::PrefixMatch(const DictPtr& dict) { |
| 330 | // Try to unwrap single dict group |
no test coverage detected