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

Unified Diff: chrome/browser/chromeos/drive/search_metadata.cc

Issue 15757009: Tiny optimization in auto completion of Drive files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/search_metadata.cc
diff --git a/chrome/browser/chromeos/drive/search_metadata.cc b/chrome/browser/chromeos/drive/search_metadata.cc
index 258d39d122958960baf4161b69fccab3780341e4..d2007a57fdabd812b61bf27b90a9a46e6f57fd8e 100644
--- a/chrome/browser/chromeos/drive/search_metadata.cc
+++ b/chrome/browser/chromeos/drive/search_metadata.cc
@@ -128,6 +128,13 @@ void MaybeAddEntryToResult(
const ResourceEntry& entry) {
DCHECK_GE(at_most_num_matches, result_candidates->size());
+ // If the candidate set is already full, and this |entry| is old, do nothing.
+ // We perform this check first in order to avoid the costly find-and-highlight
+ // or FilePath lookup as much as possible.
+ if (result_candidates->size() == at_most_num_matches &&
+ !CompareByTimestamp(entry, result_candidates->top()->entry))
+ return;
+
// Add |entry| to the result if the entry is eligible for the given
// |options| and matches the query. The base name of the entry must
// contain |query| to match the query.
@@ -141,13 +148,9 @@ void MaybeAddEntryToResult(
return;
// Make space for |entry| when appropriate.
- if (result_candidates->size() == at_most_num_matches &&
- CompareByTimestamp(entry, result_candidates->top()->entry))
+ if (result_candidates->size() == at_most_num_matches)
result_candidates->pop();
-
- // Add |entry| to the result when appropriate.
- if (result_candidates->size() < at_most_num_matches)
- result_candidates->push(new MetadataSearchResult(path, entry, highlighted));
+ result_candidates->push(new MetadataSearchResult(path, entry, highlighted));
}
// Implements SearchMetadata().
« 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