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

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

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 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 65f8635d2bb873880ecba1097646eff7b320c206..3c8f52c552e4aaf1ffba410913fa8a3123f6f493 100644
--- a/chrome/common/extensions/url_pattern_set.cc
+++ b/chrome/common/extensions/url_pattern_set.cc
@@ -4,6 +4,9 @@
#include "chrome/common/extensions/url_pattern_set.h"
+#include <algorithm>
+#include <iterator>
+
#include "chrome/common/extensions/url_pattern.h"
#include "googleurl/src/gurl.h"
@@ -11,39 +14,38 @@
void URLPatternSet::CreateUnion(const URLPatternSet& set1,
const URLPatternSet& set2,
URLPatternSet* out) {
- const URLPatternList list1 = set1.patterns();
- const URLPatternList list2 = set2.patterns();
-
out->ClearPatterns();
-
- for (size_t i = 0; i < list1.size(); ++i)
- out->AddPattern(list1.at(i));
-
- for (size_t i = 0; i < list2.size(); ++i)
- out->AddPattern(list2.at(i));
+ std::set_union(set1.patterns_.begin(), set1.patterns_.end(),
+ set2.patterns_.begin(), set2.patterns_.end(),
+ std::inserter<std::set<URLPattern> >(
+ out->patterns_, out->patterns_.begin()));
}
-URLPatternSet::URLPatternSet() {
-}
+URLPatternSet::URLPatternSet() {}
URLPatternSet::URLPatternSet(const URLPatternSet& rhs)
- : patterns_(rhs.patterns_) {
-}
+ : patterns_(rhs.patterns_) {}
-URLPatternSet::~URLPatternSet() {
-}
+URLPatternSet::URLPatternSet(const std::set<URLPattern>& patterns)
+ : patterns_(patterns) {}
+
+URLPatternSet::~URLPatternSet() {}
URLPatternSet& URLPatternSet::operator=(const URLPatternSet& rhs) {
patterns_ = rhs.patterns_;
return *this;
}
+bool URLPatternSet::operator==(const URLPatternSet& other) const {
+ return patterns_ == other.patterns_;
+}
+
bool URLPatternSet::is_empty() const {
return patterns_.empty();
}
void URLPatternSet::AddPattern(const URLPattern& pattern) {
- patterns_.push_back(pattern);
+ patterns_.insert(pattern);
}
void URLPatternSet::ClearPatterns() {
@@ -51,7 +53,7 @@ void URLPatternSet::ClearPatterns() {
}
bool URLPatternSet::MatchesURL(const GURL& url) const {
- for (URLPatternList::const_iterator pattern = patterns_.begin();
+ for (URLPatternSet::const_iterator pattern = patterns_.begin();
pattern != patterns_.end(); ++pattern) {
if (pattern->MatchesURL(url))
return true;
@@ -63,9 +65,9 @@ bool URLPatternSet::MatchesURL(const GURL& url) const {
bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const {
// Two extension extents overlap if there is any one URL that would match at
// least one pattern in each of the extents.
- for (URLPatternList::const_iterator i = patterns_.begin();
+ for (URLPatternSet::const_iterator i = patterns_.begin();
i != patterns_.end(); ++i) {
- for (URLPatternList::const_iterator j = other.patterns().begin();
+ for (URLPatternSet::const_iterator j = other.patterns().begin();
j != other.patterns().end(); ++j) {
if (i->OverlapsWith(*j))
return true;
« 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