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

Unified Diff: chrome/common/extensions/url_pattern_set.cc

Issue 10443105: Take 2 at implementing activeTab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: empty -> is_empty Created 8 years, 6 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 | « chrome/common/extensions/url_pattern_set.h ('k') | chrome/common/extensions/url_pattern_set_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/url_pattern_set.cc
diff --git a/chrome/common/extensions/url_pattern_set.cc b/chrome/common/extensions/url_pattern_set.cc
index c84df1464f4127cd2fd07df154c147fb9fbc56b0..60f8e16b2b9dfae1007d0ded61d18edebb5a84ee 100644
--- a/chrome/common/extensions/url_pattern_set.cc
+++ b/chrome/common/extensions/url_pattern_set.cc
@@ -8,6 +8,7 @@
#include <iterator>
#include "base/logging.h"
+#include "base/memory/linked_ptr.h"
#include "base/values.h"
#include "chrome/common/extensions/extension_error_utils.h"
#include "chrome/common/extensions/url_pattern.h"
@@ -53,6 +54,39 @@ void URLPatternSet::CreateUnion(const URLPatternSet& set1,
out->patterns_, out->patterns_.begin()));
}
+// static
+void URLPatternSet::CreateUnion(const std::vector<URLPatternSet>& sets,
+ URLPatternSet* out) {
+ out->ClearPatterns();
+ if (sets.empty())
+ return;
+
+ // N-way union algorithm is basic O(nlog(n)) merge algorithm.
+ //
+ // Do the first merge step into a working set so that we don't mutate any of
+ // the input.
+ std::vector<URLPatternSet> working;
+ for (size_t i = 0; i < sets.size(); i += 2) {
+ if (i + 1 < sets.size()) {
+ URLPatternSet u;
+ URLPatternSet::CreateUnion(sets[i], sets[i + 1], &u);
+ working.push_back(u);
+ } else {
+ working.push_back(sets[i]);
+ }
+ }
+
+ for (size_t skip = 1; skip < working.size(); skip *= 2) {
+ for (size_t i = 0; i < (working.size() - skip); i += skip) {
+ URLPatternSet u;
+ URLPatternSet::CreateUnion(working[i], working[i + skip], &u);
+ working[i].patterns_.swap(u.patterns_);
+ }
+ }
+
+ out->patterns_.swap(working[0].patterns_);
+}
+
URLPatternSet::URLPatternSet() {}
URLPatternSet::URLPatternSet(const URLPatternSet& rhs)
@@ -76,6 +110,10 @@ bool URLPatternSet::is_empty() const {
return patterns_.empty();
}
+size_t URLPatternSet::size() const {
+ return patterns_.size();
+}
+
void URLPatternSet::AddPattern(const URLPattern& pattern) {
patterns_.insert(pattern);
}
« no previous file with comments | « chrome/common/extensions/url_pattern_set.h ('k') | chrome/common/extensions/url_pattern_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698