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

Unified Diff: content/browser/indexed_db/indexed_db_transaction_coordinator.cc

Issue 23490012: Replace O(n^2) set intersection test with O(n) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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: content/browser/indexed_db/indexed_db_transaction_coordinator.cc
diff --git a/content/browser/indexed_db/indexed_db_transaction_coordinator.cc b/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
index 1f5100d26ac37748531001b27b1b807e4f479fbe..e7ceb3f3ce0e7e3167fe2bf60b5e8d2bbf73cb40 100644
--- a/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
+++ b/content/browser/indexed_db/indexed_db_transaction_coordinator.cc
@@ -105,11 +105,17 @@ void IndexedDBTransactionCoordinator::ProcessStartedTransactions() {
}
}
-static bool DoScopesOverlap(const std::set<int64>& scope1,
- const std::set<int64>& scope2) {
- for (std::set<int64>::const_iterator it = scope1.begin(); it != scope1.end();
- ++it) {
- if (scope2.find(*it) != scope2.end())
+template<typename T>
+static bool DoSetsIntersect(const std::set<T>& set1,
+ const std::set<T>& set2) {
+ typename std::set<T>::const_iterator it1 = set1.begin();
+ typename std::set<T>::const_iterator it2 = set2.begin();
+ while (it1 != set1.end() && it2 != set2.end()) {
+ if (*it1 < *it2)
+ ++it1;
+ else if (*it2 < *it1)
+ ++it2;
+ else
return true;
}
return false;
@@ -134,7 +140,7 @@ bool IndexedDBTransactionCoordinator::CanRunTransaction(
++it) {
IndexedDBTransaction* other = *it;
if (other->mode() == indexed_db::TRANSACTION_READ_WRITE &&
- DoScopesOverlap(transaction->scope(), other->scope()))
+ DoSetsIntersect(transaction->scope(), other->scope()))
return false;
}
for (list_set<IndexedDBTransaction*>::const_iterator it =
@@ -144,7 +150,7 @@ bool IndexedDBTransactionCoordinator::CanRunTransaction(
DCHECK(it != queued_transactions_.end());
IndexedDBTransaction* other = *it;
if (other->mode() == indexed_db::TRANSACTION_READ_WRITE &&
- DoScopesOverlap(transaction->scope(), other->scope()))
+ DoSetsIntersect(transaction->scope(), other->scope()))
return false;
}
return true;
« 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