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

Side by Side Diff: sync/internal_api/base_node.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, 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 unified diff | Download patch
« no previous file with comments | « no previous file | sync/syncable/directory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/base_node.h" 5 #include "sync/internal_api/public/base_node.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 int64 BaseNode::GetFirstChildId() const { 211 int64 BaseNode::GetFirstChildId() const {
212 syncable::Id id_string = GetEntry()->GetFirstChildId(); 212 syncable::Id id_string = GetEntry()->GetFirstChildId();
213 if (id_string.IsRoot()) 213 if (id_string.IsRoot())
214 return kInvalidId; 214 return kInvalidId;
215 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string); 215 return IdToMetahandle(GetTransaction()->GetWrappedTrans(), id_string);
216 } 216 }
217 217
218 int BaseNode::GetTotalNodeCount() const { 218 int BaseNode::GetTotalNodeCount() const {
219 syncable::BaseTransaction* trans = GetTransaction()->GetWrappedTrans(); 219 return GetEntry()->GetTotalNodeCount();
220
221 int count = 1; // Start with one to include the node itself.
222
223 std::stack<int64> stack;
224 stack.push(GetFirstChildId());
225 while (!stack.empty()) {
226 int64 handle = stack.top();
227 stack.pop();
228 if (handle == kInvalidId)
229 continue;
230 count++;
231 syncable::Entry entry(trans, syncable::GET_BY_HANDLE, handle);
232 if (!entry.good())
233 continue;
234 syncable::Id successor_id = entry.GetSuccessorId();
235 if (!successor_id.IsRoot())
236 stack.push(IdToMetahandle(trans, successor_id));
237 if (!entry.Get(syncable::IS_DIR))
238 continue;
239 syncable::Id child_id = entry.GetFirstChildId();
240 if (!child_id.IsRoot())
241 stack.push(IdToMetahandle(trans, child_id));
242 }
243 return count;
244 } 220 }
245 221
246 DictionaryValue* BaseNode::GetSummaryAsValue() const { 222 DictionaryValue* BaseNode::GetSummaryAsValue() const {
247 DictionaryValue* node_info = new DictionaryValue(); 223 DictionaryValue* node_info = new DictionaryValue();
248 node_info->SetString("id", base::Int64ToString(GetId())); 224 node_info->SetString("id", base::Int64ToString(GetId()));
249 node_info->SetBoolean("isFolder", GetIsFolder()); 225 node_info->SetBoolean("isFolder", GetIsFolder());
250 node_info->SetString("title", GetTitle()); 226 node_info->SetString("title", GetTitle());
251 node_info->Set("type", ModelTypeToValue(GetModelType())); 227 node_info->Set("type", ModelTypeToValue(GetModelType()));
252 return node_info; 228 return node_info;
253 } 229 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 const sync_pb::EntitySpecifics& specifics) { 344 const sync_pb::EntitySpecifics& specifics) {
369 ModelType type = GetModelTypeFromSpecifics(specifics); 345 ModelType type = GetModelTypeFromSpecifics(specifics);
370 DCHECK_NE(UNSPECIFIED, type); 346 DCHECK_NE(UNSPECIFIED, type);
371 if (GetModelType() != UNSPECIFIED) { 347 if (GetModelType() != UNSPECIFIED) {
372 DCHECK_EQ(GetModelType(), type); 348 DCHECK_EQ(GetModelType(), type);
373 } 349 }
374 unencrypted_data_.CopyFrom(specifics); 350 unencrypted_data_.CopyFrom(specifics);
375 } 351 }
376 352
377 } // namespace syncer 353 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | sync/syncable/directory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698