Commit 39199ef9 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Tiny optimization in auto completion of Drive files.

This patch filters out candidates based on the timestamp,
before testing filename match or accessing resource metadata
DB for file path resolution.

BUG=none
TEST=With debug build and with a large account, type "a" in the search box
of Files.app. It should become faster.

Review URL: https://chromiumcodereview.appspot.com/15757009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202404 0039d316-1c4b-4281-b951-d872f2087c98
parent 07608b1e
...@@ -127,6 +127,13 @@ void MaybeAddEntryToResult( ...@@ -127,6 +127,13 @@ void MaybeAddEntryToResult(
const ResourceEntry& entry) { const ResourceEntry& entry) {
DCHECK_GE(at_most_num_matches, result_candidates->size()); 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 // 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 // |options| and matches the query. The base name of the entry must
// contains |query| to match the query. // contains |query| to match the query.
...@@ -140,13 +147,9 @@ void MaybeAddEntryToResult( ...@@ -140,13 +147,9 @@ void MaybeAddEntryToResult(
return; return;
// Make space for |entry| when appropriate. // Make space for |entry| when appropriate.
if (result_candidates->size() == at_most_num_matches && if (result_candidates->size() == at_most_num_matches)
CompareByTimestamp(entry, result_candidates->top()->entry))
result_candidates->pop(); result_candidates->pop();
result_candidates->push(new MetadataSearchResult(path, entry, highlighted));
// Add |entry| to the result when appropriate.
if (result_candidates->size() < at_most_num_matches)
result_candidates->push(new MetadataSearchResult(path, entry, highlighted));
} }
// Implements SearchMetadata(). // Implements SearchMetadata().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment