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

Unified Diff: components/subresource_filter/core/common/fuzzy_pattern_matching.cc

Issue 2793993002: [subresource_filter] Replace KMP by std::search. (Closed)
Patch Set: Fix DCHECK. Created 3 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
Index: components/subresource_filter/core/common/fuzzy_pattern_matching.cc
diff --git a/components/subresource_filter/core/common/fuzzy_pattern_matching.cc b/components/subresource_filter/core/common/fuzzy_pattern_matching.cc
index 96b0f5cb7876d04fa4e0b762985f367b657c8ccb..f0a4dfd50aa9c87c0f1d4f37060fea2b6acac6fa 100644
--- a/components/subresource_filter/core/common/fuzzy_pattern_matching.cc
+++ b/components/subresource_filter/core/common/fuzzy_pattern_matching.cc
@@ -4,6 +4,8 @@
#include "components/subresource_filter/core/common/fuzzy_pattern_matching.h"
+#include <algorithm>
+
namespace subresource_filter {
namespace {
@@ -35,4 +37,23 @@ bool EndsWithFuzzy(base::StringPiece text, base::StringPiece subpattern) {
subpattern);
}
+size_t FindFuzzy(base::StringPiece text,
+ base::StringPiece subpattern,
+ size_t from) {
+ if (from > text.size())
+ return base::StringPiece::npos;
+ if (subpattern.empty())
+ return from;
+
+ auto fuzzy_compare = [](char text_char, char subpattern_char) {
+ return text_char == subpattern_char ||
+ (subpattern_char == kSeparatorPlaceholder && IsSeparator(text_char));
+ };
+
+ base::StringPiece::const_iterator found =
+ std::search(text.begin() + from, text.end(), subpattern.begin(),
+ subpattern.end(), fuzzy_compare);
+ return found == text.end() ? base::StringPiece::npos : found - text.begin();
+}
+
} // namespace subresource_filter

Powered by Google App Engine
This is Rietveld 408576698