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

Unified Diff: chrome/browser/safe_browsing/safe_browsing_store.cc

Issue 8349018: Safe-browsing SBAddPrefix from vector to deque. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 2 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: chrome/browser/safe_browsing/safe_browsing_store.cc
diff --git a/chrome/browser/safe_browsing/safe_browsing_store.cc b/chrome/browser/safe_browsing/safe_browsing_store.cc
index c699c136c3ee01687cccae7dfecc60a7eb887acd..76f8d66123d8a34f4eec54f7b7699561b4cdbed1 100644
--- a/chrome/browser/safe_browsing/safe_browsing_store.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_store.cc
@@ -18,25 +18,25 @@ namespace {
//
// |predAS| provides add < sub, |predSA| provides sub < add, for the
// tightest compare appropriate (see calls in SBProcessSubs).
-template <class S, class A, typename PredAS, typename PredSA>
-void KnockoutSubs(std::vector<S>* subs,
- std::vector<A>* adds,
+template <typename CS, typename CA, typename PredAS, typename PredSA>
jar (doing other things) 2011/10/21 19:10:45 I really didn't like these two letter names. The w
Scott Hess - ex-Googler 2011/10/21 23:39:32 Yeah, I just couldn't think of anything quality to
+void KnockoutSubs(CS* subs,
+ CA* adds,
PredAS predAS, PredSA predSA,
- std::vector<A>* adds_removed) {
+ CA* adds_removed) {
// Keep a pair of output iterators for writing kept items. Due to
// deletions, these may lag the main iterators. Using erase() on
// individual items would result in O(N^2) copies. Using std::list
// would work around that, at double or triple the memory cost.
- typename std::vector<A>::iterator add_out = adds->begin();
- typename std::vector<S>::iterator sub_out = subs->begin();
+ typename CA::iterator add_out = adds->begin();
+ typename CS::iterator sub_out = subs->begin();
- // Current location in vectors.
+ // Current location in containers.
// TODO(shess): I want these to be const_iterator, but then
// std::copy() gets confused. Could snag a const_iterator add_end,
// or write an inline std::copy(), but it seems like I'm doing
// something wrong.
- typename std::vector<A>::iterator add_iter = adds->begin();
jar (doing other things) 2011/10/21 19:10:45 I'm *not* an expert on templates... but can't you
Scott Hess - ex-Googler 2011/10/21 23:39:32 I don't understand the question. Sometimes a cont
- typename std::vector<S>::iterator sub_iter = subs->begin();
+ typename CA::iterator add_iter = adds->begin();
+ typename CS::iterator sub_iter = subs->begin();
while (add_iter != adds->end() && sub_iter != subs->end()) {
// If |*sub_iter| < |*add_iter|, retain the sub.
@@ -66,18 +66,17 @@ void KnockoutSubs(std::vector<S>* subs,
// Remove items in |removes| from |full_hashes|. |full_hashes| and
// |removes| should be ordered by SBAddPrefix component.
-template <class T>
-void RemoveMatchingPrefixes(const std::vector<SBAddPrefix>& removes,
- std::vector<T>* full_hashes) {
+template <typename CT, typename CA>
+void RemoveMatchingPrefixes(const CA& removes, CT* full_hashes) {
// This is basically an inline of std::set_difference().
// Unfortunately, that algorithm requires that the two iterator
// pairs use the same value types.
// Where to store kept items.
- typename std::vector<T>::iterator out = full_hashes->begin();
+ typename CT::iterator out = full_hashes->begin();
- typename std::vector<T>::iterator hash_iter = full_hashes->begin();
- std::vector<SBAddPrefix>::const_iterator remove_iter = removes.begin();
+ typename CT::iterator hash_iter = full_hashes->begin();
+ typename CA::const_iterator remove_iter = removes.begin();
while (hash_iter != full_hashes->end() && remove_iter != removes.end()) {
// Keep items less than |*remove_iter|.
@@ -104,14 +103,14 @@ void RemoveMatchingPrefixes(const std::vector<SBAddPrefix>& removes,
full_hashes->erase(out, hash_iter);
}
-// Remove deleted items (|chunk_id| in |del_set|) from the vector.
-template <class T>
-void RemoveDeleted(std::vector<T>* vec, const base::hash_set<int32>& del_set) {
+// Remove deleted items (|chunk_id| in |del_set|) from the container.
+template <typename CT>
+void RemoveDeleted(CT* vec, const base::hash_set<int32>& del_set) {
DCHECK(vec);
- // Scan through the items read, dropping the items in |del_set|.
- typename std::vector<T>::iterator add_iter = vec->begin();
- for (typename std::vector<T>::iterator iter = add_iter;
+ // Move items from |iter| to |add_iter|, skipping items in |del_set|.
+ typename CT::iterator add_iter = vec->begin();
+ for (typename CT::iterator iter = add_iter;
iter != vec->end(); ++iter) {
if (del_set.count(iter->chunk_id) == 0) {
*add_iter = *iter;
@@ -131,7 +130,7 @@ enum MissTypes {
} // namespace
-void SBCheckPrefixMisses(const std::vector<SBAddPrefix>& add_prefixes,
+void SBCheckPrefixMisses(const SBAddPrefixContainer& add_prefixes,
const std::set<SBPrefix>& prefix_misses) {
if (prefix_misses.empty())
return;
@@ -148,9 +147,10 @@ void SBCheckPrefixMisses(const std::vector<SBAddPrefix>& add_prefixes,
// prefix, it is not sufficient to count the number of elements
// present in both collections.
std::set<SBPrefix> false_misses(prefix_misses.begin(), prefix_misses.end());
- for (size_t i = 0; i < add_prefixes.size(); ++i) {
+ for (SBAddPrefixContainer::const_iterator iter = add_prefixes.begin();
+ iter != add_prefixes.end(); ++iter) {
// |erase()| on an absent element should cost like |find()|.
- false_misses.erase(add_prefixes[i].prefix);
+ false_misses.erase(iter->prefix);
}
// Record a hit for prefixes which we shouldn't have sent in the
@@ -164,7 +164,7 @@ void SBCheckPrefixMisses(const std::vector<SBAddPrefix>& add_prefixes,
// bloom-filter false-positive rate.
}
-void SBProcessSubs(std::vector<SBAddPrefix>* add_prefixes,
+void SBProcessSubs(SBAddPrefixContainer* add_prefixes,
std::vector<SBSubPrefix>* sub_prefixes,
std::vector<SBAddFullHash>* add_full_hashes,
std::vector<SBSubFullHash>* sub_full_hashes,
@@ -186,7 +186,7 @@ void SBProcessSubs(std::vector<SBAddPrefix>* add_prefixes,
SBAddPrefixHashLess<SBSubFullHash,SBSubFullHash>);
// Factor out the prefix subs.
- std::vector<SBAddPrefix> removed_adds;
+ SBAddPrefixContainer removed_adds;
KnockoutSubs(sub_prefixes, add_prefixes,
SBAddPrefixLess<SBAddPrefix,SBSubPrefix>,
SBAddPrefixLess<SBSubPrefix,SBAddPrefix>,

Powered by Google App Engine
This is Rietveld 408576698