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

Unified Diff: sync/syncable/directory.cc

Issue 15322003: sync: Count nodes more efficiently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement suggestions from review Created 7 years, 7 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 | « sync/syncable/directory.h ('k') | sync/syncable/entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/syncable/directory.cc
diff --git a/sync/syncable/directory.cc b/sync/syncable/directory.cc
index a844e66e4cd17243facb911a0243e5ce431a27c2..9cbb73c4f8cc448af07e2ae801db6f1679fc62f3 100644
--- a/sync/syncable/directory.cc
+++ b/sync/syncable/directory.cc
@@ -321,6 +321,46 @@ bool Directory::GetChildHandlesByHandle(
return true;
}
+int Directory::GetTotalNodeCount(
+ BaseTransaction* trans,
+ EntryKernel* kernel) const {
+ if (!SyncAssert(this == trans->directory(), FROM_HERE,
+ "Directories don't match", trans))
+ return false;
+
+ int count = 1;
+ std::deque<const OrderedChildSet*> child_sets;
+
+ GetChildSetForKernel(trans, kernel, &child_sets);
+ while (!child_sets.empty()) {
+ const OrderedChildSet* set = child_sets.front();
+ child_sets.pop_front();
+ for (OrderedChildSet::const_iterator it = set->begin();
+ it != set->end(); ++it) {
+ count++;
+ GetChildSetForKernel(trans, *it, &child_sets);
+ }
+ }
+
+ return count;
+}
+
+void Directory::GetChildSetForKernel(
+ BaseTransaction* trans,
+ EntryKernel* kernel,
+ std::deque<const OrderedChildSet*>* child_sets) const {
+ if (!kernel->ref(IS_DIR))
+ return; // Not a directory => no children.
+
+ const OrderedChildSet* descendants =
+ kernel_->parent_child_index->GetChildren(kernel->ref(ID));
+ if (!descendants)
+ return; // This directory has no children.
+
+ // Add our children to the list of items to be traversed.
+ child_sets->push_back(descendants);
+}
+
EntryKernel* Directory::GetRootEntry() {
return GetEntryById(Id());
}
« no previous file with comments | « sync/syncable/directory.h ('k') | sync/syncable/entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698