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(). |