From cc438b8f400c4a630edde2874465cbe261b44a9b Mon Sep 17 00:00:00 2001 From: "brettw%gmail.com" Date: Wed, 21 Dec 2005 18:31:22 +0000 Subject: [PATCH] Bug 321129 r=annie.sullivan Move simple bookmark short-circuit to functions. git-svn-id: svn://10.0.0.236/trunk@186374 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/places/src/nsNavHistory.cpp | 100 ++++++++++++------ .../components/places/src/nsNavHistory.h | 4 + 2 files changed, 72 insertions(+), 32 deletions(-) diff --git a/mozilla/browser/components/places/src/nsNavHistory.cpp b/mozilla/browser/components/places/src/nsNavHistory.cpp index c90fd6312d8..61cd08ccd33 100644 --- a/mozilla/browser/components/places/src/nsNavHistory.cpp +++ b/mozilla/browser/components/places/src/nsNavHistory.cpp @@ -153,6 +153,8 @@ static PRInt32 GetTLDType(const nsString& aHostTail); static void GetUnreversedHostname(const nsString& aBackward, nsAString& aForward); static PRBool IsNumericHostName(const nsString& aHost); +static PRBool IsSimpleBookmarksQuery(nsINavHistoryQuery** aQueries, + PRUint32 aQueryCount); static void ParseSearchQuery(const nsString& aQuery, nsStringArray* aTerms); inline void ReverseString(const nsString& aInput, nsAString& aReversed) @@ -1273,38 +1275,8 @@ nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, PRUint32 aQueryCount // In the simple case where we're just querying children of a single bookmark // folder, we can avoid the complexity of the grouper and just hand back // the results. - do { - if (aQueryCount != 1) break; - - nsINavHistoryQuery *query = aQueries[0]; - PRUint32 folderCount; - query->GetFolderCount(&folderCount); - if (folderCount != 1) break; - - PRBool hasIt; - query->GetHasBeginTime(&hasIt); - if (hasIt) break; - query->GetHasEndTime(&hasIt); - if (hasIt) break; - query->GetHasDomain(&hasIt); - if (hasIt) break; - - nsRefPtr result = NewHistoryResult(aQueries, - aQueryCount, - options); - NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); - - rv = result->Init(); - NS_ENSURE_SUCCESS(rv, rv); - - rv = nsNavBookmarks::GetBookmarksService()-> - QueryFolderChildren(aQueries[0], options, result->GetTopLevel()); - - NS_ENSURE_SUCCESS(rv, rv); - result->FilledAllResults(); - NS_STATIC_CAST(nsRefPtr, result).swap(*_retval); - return NS_OK; - } while (0); + if (IsSimpleBookmarksQuery(aQueries, aQueryCount)) + return FillSimpleBookmarksQuery(aQueries, aQueryCount, options, _retval); PRBool asVisits = options->ResultType() == nsINavHistoryQueryOptions::RESULT_TYPE_VISIT; @@ -2253,6 +2225,37 @@ nsNavHistory::BindQueryClauseParameters(mozIStorageStatement* statement, } +// nsNavHistory::FillSimpleBookmarksQuery +// +// When we know we have a simple bookmarks query, which consists of a single +// clause for a bookmark folder with no other sorting or grouping, this +// function can quickly compute the results and avoid overhead of general +// DB queries and grouping. + +nsresult +nsNavHistory::FillSimpleBookmarksQuery(nsINavHistoryQuery** aQueries, + PRUint32 aQueryCount, + nsNavHistoryQueryOptions* aOptions, + nsINavHistoryResult** _retval) +{ + nsRefPtr result = NewHistoryResult(aQueries, + aQueryCount, + aOptions); + NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); + + nsresult rv = result->Init(); + NS_ENSURE_SUCCESS(rv, rv); + + rv = nsNavBookmarks::GetBookmarksService()-> + QueryFolderChildren(aQueries[0], aOptions, result->GetTopLevel()); + + NS_ENSURE_SUCCESS(rv, rv); + result->FilledAllResults(); + NS_STATIC_CAST(nsRefPtr, result).swap(*_retval); + return NS_OK; +} + + // nsNavHistory::ResultsAsList // @@ -3108,6 +3111,39 @@ PRBool IsNumericHostName(const nsString& aHost) } +// IsSimpleBookmarksQuery +// +// Determines if this set of queries is a simple bookmarks query for a +// folder with no other constraints. In these common cases, we can more +// efficiently compute the results. + +static PRBool IsSimpleBookmarksQuery(nsINavHistoryQuery** aQueries, + PRUint32 aQueryCount) +{ + if (aQueryCount != 1) + return PR_FALSE; + + nsINavHistoryQuery *query = aQueries[0]; + PRUint32 folderCount; + query->GetFolderCount(&folderCount); + if (folderCount != 1) + return PR_FALSE; + + PRBool hasIt; + query->GetHasBeginTime(&hasIt); + if (hasIt) + return PR_FALSE; + query->GetHasEndTime(&hasIt); + if (hasIt) + return PR_FALSE; + query->GetHasDomain(&hasIt); + if (hasIt) + return PR_FALSE; + + return PR_TRUE; +} + + // ParseSearchQuery // // This just breaks the query up into words. We don't do anything fancy, diff --git a/mozilla/browser/components/places/src/nsNavHistory.h b/mozilla/browser/components/places/src/nsNavHistory.h index b2461afcb44..ca66bcba545 100644 --- a/mozilla/browser/components/places/src/nsNavHistory.h +++ b/mozilla/browser/components/places/src/nsNavHistory.h @@ -655,6 +655,10 @@ protected: nsINavHistoryQuery* aQuery, PRInt32* aParamCount); + nsresult FillSimpleBookmarksQuery(nsINavHistoryQuery** aQueries, + PRUint32 aQueryCount, + nsNavHistoryQueryOptions* aOptions, + nsINavHistoryResult** _retval); nsresult ResultsAsList(mozIStorageStatement* statement, nsNavHistoryQueryOptions* aOptions, nsCOMArray* aResults);