Index: extensions/common/matcher/substring_set_matcher.cc |
diff --git a/extensions/common/matcher/substring_set_matcher.cc b/extensions/common/matcher/substring_set_matcher.cc |
index b5fdae6da37f80c3b9a1b963e1cbb052e54af8b5..27a950fb737c98dfb351825244ef7515b71a8b3b 100644 |
--- a/extensions/common/matcher/substring_set_matcher.cc |
+++ b/extensions/common/matcher/substring_set_matcher.cc |
@@ -101,26 +101,27 @@ void SubstringSetMatcher::RebuildAhoCorasickTree() { |
void SubstringSetMatcher::InsertPatternIntoAhoCorasickTree( |
const StringPattern* pattern) { |
const std::string& text = pattern->pattern(); |
- size_t text_length = text.length(); |
+ const std::string::const_iterator text_end = text.end(); |
- // Iterators on the tree and the text. |
+ std::string::const_iterator text_iter = text.begin(); |
int current_node = 0; |
- size_t text_pos = 0; |
// Follow existing paths for as long as possible. |
- while (text_pos < text_length && |
- tree_[current_node].HasEdge(text[text_pos])) { |
- current_node = tree_[current_node].GetEdge(text[text_pos]); |
- ++text_pos; |
+ int edge_to; |
+ while (text_iter != text_end && |
+ (edge_to = tree_[current_node].GetEdge(*text_iter)) != -1) { |
+ current_node = edge_to; |
+ ++text_iter; |
} |
// Create new nodes if necessary. |
- while (text_pos < text_length) { |
- AhoCorasickNode new_node; |
- tree_.push_back(new_node); |
- tree_[current_node].SetEdge(text[text_pos], tree_.size() - 1); |
- current_node = tree_.size() - 1; |
- ++text_pos; |
+ int new_node_position = tree_.size(); |
+ while (text_iter != text_end) { |
+ tree_.push_back(AhoCorasickNode()); |
+ tree_[current_node].SetEdge(*text_iter, new_node_position); |
+ current_node = new_node_position; |
+ ++text_iter; |
+ ++new_node_position; |
} |
// Register match. |