Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: extensions/common/matcher/substring_set_matcher.cc

Issue 14856016: Performance optimization of SubstringSetMatcher::InsertPatternIntoAhoCorasickTree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor tweak Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698