Bug 1446951 - 7 - Remove some internal use of GetHas* APIs. r=standard8
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 20 Mar 2018 01:07:01 +0100
changeset 409546 7a3803b96fd1491aad494cdbe49e51fcffd20da4
parent 409545 53282ceffd41bd478af997457142365232fb3150
child 409547 2c4a64ef1e7011ff86a0d6921726b6e28d292fe6
push id101247
push usernerli@mozilla.com
push dateThu, 22 Mar 2018 23:00:51 +0000
treeherdermozilla-inbound@02e384bdf97d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8
bugs1446951
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1446951 - 7 - Remove some internal use of GetHas* APIs. r=standard8 MozReview-Commit-ID: E4JudYNzLFT
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsNavHistoryQuery.cpp
toolkit/components/places/nsNavHistoryQuery.h
toolkit/components/places/nsNavHistoryResult.cpp
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -790,23 +790,21 @@ nsNavHistory::NormalizeTime(uint32_t aRe
 //    change operations as simple instead of complex.
 
 uint32_t
 nsNavHistory::GetUpdateRequirements(const RefPtr<nsNavHistoryQuery>& aQuery,
                                     nsNavHistoryQueryOptions* aOptions,
                                     bool* aHasSearchTerms)
 {
   // first check if there are search terms
-  *aHasSearchTerms = false;
-  aQuery->GetHasSearchTerms(aHasSearchTerms);
+  bool hasSearchTerms = *aHasSearchTerms = !aQuery->SearchTerms().IsEmpty();
 
   bool nonTimeBasedItems = false;
   bool domainBasedItems = false;
 
-  bool hasSearchTerms = !aQuery->SearchTerms().IsEmpty();
   if (aQuery->Folders().Length() > 0 ||
       aQuery->OnlyBookmarked() ||
       aQuery->Tags().Length() > 0 ||
       (aOptions->QueryType() == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS &&
         hasSearchTerms)) {
     return QUERYUPDATE_COMPLEX_WITH_BOOKMARKS;
   }
 
@@ -903,18 +901,17 @@ nsNavHistory::EvaluateQueryForNode(const
     nsresult rv = FilterResultSet(nullptr, inputSet, &filteredSet, aQuery, aOptions);
     if (NS_FAILED(rv))
       return false;
     if (!filteredSet.Count())
       return false;
   }
 
   // --- domain/host matching ---
-  aQuery->GetHasDomain(&hasIt);
-  if (hasIt) {
+  if (!aQuery->Domain().IsVoid()) {
     if (!nodeUri) {
       // lazy creation of nodeUri, which might be checked for multiple queries
       if (NS_FAILED(NS_NewURI(getter_AddRefs(nodeUri), aNode->mURI)))
         return false;
     }
     nsAutoCString asciiRequest;
     if (NS_FAILED(AsciiHostNameFromHostString(aQuery->Domain(), asciiRequest)))
       return false;
@@ -2172,18 +2169,17 @@ nsNavHistory::ConstructQueryString(
   nsresult rv;
   aParamsPresent = false;
 
   int32_t sortingMode = aOptions->SortingMode();
   NS_ASSERTION(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE &&
                sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING,
                "Invalid sortingMode found while building query!");
 
-  bool hasSearchTerms = false;
-  aQuery->GetHasSearchTerms(&hasSearchTerms);
+  bool hasSearchTerms = !aQuery->SearchTerms().IsEmpty();
 
   nsAutoCString tagsSqlFragment;
   GetTagsSqlFragment(GetTagsFolder(),
                      NS_LITERAL_CSTRING("h.id"),
                      hasSearchTerms,
                      tagsSqlFragment);
 
   if (IsOptimizableHistoryQuery(aQuery, aOptions,
@@ -3170,20 +3166,19 @@ nsNavHistory::QueryToSelectClause(const 
       clause.Condition("visit_date >=").Param(":begin_time");
     // end time
     if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt)
       clause.Condition("visit_date <=").Param(":end_time");
     clause.Str(" LIMIT 1)");
   }
 
   // search terms
-  bool hasSearchTerms;
   int32_t searchBehavior = mozIPlacesAutoComplete::BEHAVIOR_HISTORY |
                            mozIPlacesAutoComplete::BEHAVIOR_BOOKMARK;
-  if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasSearchTerms)) && hasSearchTerms) {
+  if (!aQuery->SearchTerms().IsEmpty()) {
     // Re-use the autocomplete_match function.  Setting the behavior to match
     // history or typed history or bookmarks or open pages will match almost
     // everything.
     clause.Condition("AUTOCOMPLETE_MATCH(").Param(":search_string")
           .Str(", h.url, page_title, tags, ")
           .Str(nsPrintfCString("1, 1, 1, 1, %d, %d)",
                                mozIPlacesAutoComplete::MATCH_ANYWHERE_UNMODIFIED,
                                searchBehavior).get());
@@ -3201,36 +3196,35 @@ nsNavHistory::QueryToSelectClause(const 
   // only bookmarked, has no affect on bookmarks-only queries
   if (aOptions->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS &&
       aQuery->OnlyBookmarked())
     clause.Condition("EXISTS (SELECT b.fk FROM moz_bookmarks b WHERE b.type = ")
           .Str(nsPrintfCString("%d", nsNavBookmarks::TYPE_BOOKMARK).get())
           .Str("AND b.fk = h.id)");
 
   // domain
-  if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) {
+  if (!aQuery->Domain().IsVoid()) {
     bool domainIsHost = false;
     aQuery->GetDomainIsHost(&domainIsHost);
     if (domainIsHost)
       clause.Condition("h.rev_host =").Param(":domain_lower");
     else
       // see domain setting in BindQueryClauseParameters for why we do this
       clause.Condition("h.rev_host >=").Param(":domain_lower")
             .Condition("h.rev_host <").Param(":domain_upper");
   }
 
   // URI
-  if (NS_SUCCEEDED(aQuery->GetHasUri(&hasIt)) && hasIt) {
+  if (aQuery->Uri()) {
     clause.Condition("h.url_hash = hash(").Param(":uri").Str(")")
           .Condition("h.url =").Param(":uri");
   }
 
   // annotation
-  aQuery->GetHasAnnotation(&hasIt);
-  if (hasIt) {
+  if (!aQuery->Annotation().IsEmpty()) {
     clause.Condition("");
     if (aQuery->AnnotationIsNot())
       clause.Str("NOT");
     clause.Str(
       "EXISTS "
         "(SELECT h.id "
          "FROM moz_annos anno "
          "JOIN moz_anno_attributes annoname "
@@ -3340,17 +3334,17 @@ nsNavHistory::BindQueryClauseParameters(
   if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt) {
     PRTime time = NormalizeTime(aQuery->EndTimeReference(),
                                 aQuery->EndTime());
     rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("end_time"), time);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // search terms
-  if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasIt)) && hasIt) {
+  if (!aQuery->SearchTerms().IsEmpty()) {
     rv = statement->BindStringByName(NS_LITERAL_CSTRING("search_string"),
                                      aQuery->SearchTerms());
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // min and max visit count
   int32_t visits = aQuery->MinVisits();
   if (visits >= 0) {
@@ -3360,17 +3354,17 @@ nsNavHistory::BindQueryClauseParameters(
 
   visits = aQuery->MaxVisits();
   if (visits >= 0) {
     rv = statement->BindInt32ByName(NS_LITERAL_CSTRING("max_visits"), visits);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // domain (see GetReversedHostname for more info on reversed host names)
-  if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) {
+  if (!aQuery->Domain().IsVoid()) {
     nsString revDomain;
     GetReversedHostname(NS_ConvertUTF8toUTF16(aQuery->Domain()), revDomain);
 
     if (aQuery->DomainIsHost()) {
       rv = statement->BindStringByName(NS_LITERAL_CSTRING("domain_lower"),
                                        revDomain);
       NS_ENSURE_SUCCESS(rv, rv);
     } else {
@@ -4181,30 +4175,25 @@ namespace {
 static int64_t
 GetSimpleBookmarksQueryFolder(const RefPtr<nsNavHistoryQuery>& aQuery,
                               const RefPtr<nsNavHistoryQueryOptions>& aOptions)
 {
   if (aQuery->Folders().Length() != 1)
     return 0;
 
   bool hasIt;
-  aQuery->GetHasBeginTime(&hasIt);
-  if (hasIt)
+  if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt)) && hasIt)
     return 0;
-  aQuery->GetHasEndTime(&hasIt);
-  if (hasIt)
+  if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt)
     return 0;
-  aQuery->GetHasDomain(&hasIt);
-  if (hasIt)
+  if (!aQuery->Domain().IsVoid())
     return 0;
-  aQuery->GetHasUri(&hasIt);
-  if (hasIt)
+  if (aQuery->Uri())
     return 0;
-  (void)aQuery->GetHasSearchTerms(&hasIt);
-  if (hasIt)
+  if (!aQuery->SearchTerms().IsEmpty())
     return 0;
   if (aQuery->Tags().Length() > 0)
     return 0;
   if (aOptions->MaxResults() > 0)
     return 0;
 
   // RESULTS_AS_TAG_CONTENTS is quite similar to a folder shortcut, but it must
   // not be treated like that, since it needs all query options.
@@ -4232,19 +4221,17 @@ inline bool isQueryWhitespace(char16_t c
 {
   return ch == ' ';
 }
 
 void ParseSearchTermsFromQuery(const RefPtr<nsNavHistoryQuery>& aQuery,
                                nsTArray<nsString>* aTerms)
 {
   int32_t lastBegin = -1;
-  bool hasSearchTerms;
-  if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasSearchTerms)) &&
-      hasSearchTerms) {
+  if (!aQuery->SearchTerms().IsEmpty()) {
     const nsString& searchTerms = aQuery->SearchTerms();
     for (uint32_t j = 0; j < searchTerms.Length(); j++) {
       if (isQueryWhitespace(searchTerms[j]) ||
           searchTerms[j] == '"') {
         if (lastBegin >= 0) {
           // found the end of a word
           aTerms->AppendElement(Substring(searchTerms, lastBegin, j - lastBegin));
           lastBegin = -1;
--- a/toolkit/components/places/nsNavHistoryQuery.cpp
+++ b/toolkit/components/places/nsNavHistoryQuery.cpp
@@ -302,20 +302,18 @@ nsNavHistory::QueryToQueryString(nsINavH
                                  NS_LITERAL_CSTRING(QUERYKEY_END_TIME),
                                  query, &nsINavHistoryQuery::GetEndTime);
     AppendUint32KeyValueIfNonzero(queryString,
                                   NS_LITERAL_CSTRING(QUERYKEY_END_TIME_REFERENCE),
                                   query, &nsINavHistoryQuery::GetEndTimeReference);
   }
 
   // search terms
-  query->GetHasSearchTerms(&hasIt);
-  if (hasIt) {
-    nsAutoString searchTerms;
-    query->GetSearchTerms(searchTerms);
+  if (!query->SearchTerms().IsEmpty()) {
+    const nsString& searchTerms = query->SearchTerms();
     nsCString escapedTerms;
     if (! NS_Escape(NS_ConvertUTF16toUTF8(searchTerms), escapedTerms,
                     url_XAlphas))
       return NS_ERROR_OUT_OF_MEMORY;
 
     AppendAmpersandIfNonempty(queryString);
     queryString += NS_LITERAL_CSTRING(QUERYKEY_SEARCH_TERMS "=");
     queryString += escapedTerms;
@@ -339,83 +337,71 @@ nsNavHistory::QueryToQueryString(nsINavH
   // only bookmarked
   AppendBoolKeyValueIfTrue(queryString,
                            NS_LITERAL_CSTRING(QUERYKEY_ONLY_BOOKMARKED),
                            query, &nsINavHistoryQuery::GetOnlyBookmarked);
 
   // domain (+ is host), only call if hasDomain, which means non-IsVoid
   // this means we may get an empty string for the domain in the result,
   // which is valid
-  query->GetHasDomain(&hasIt);
-  if (hasIt) {
+  if (!query->Domain().IsVoid()) {
     AppendBoolKeyValueIfTrue(queryString,
                              NS_LITERAL_CSTRING(QUERYKEY_DOMAIN_IS_HOST),
                              query, &nsINavHistoryQuery::GetDomainIsHost);
-    nsAutoCString domain;
-    nsresult rv = query->GetDomain(domain);
-    NS_ENSURE_SUCCESS(rv, rv);
+    const nsCString& domain = query->Domain();
     nsCString escapedDomain;
     bool success = NS_Escape(domain, escapedDomain, url_XAlphas);
     NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
 
     AppendAmpersandIfNonempty(queryString);
     queryString.AppendLiteral(QUERYKEY_DOMAIN "=");
     queryString.Append(escapedDomain);
   }
 
   // uri
-  query->GetHasUri(&hasIt);
-  if (hasIt) {
-    nsCOMPtr<nsIURI> uri;
-    query->GetUri(getter_AddRefs(uri));
-    NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); // hasURI should tell is if invalid
+  if (query->Uri()) {
+    nsCOMPtr<nsIURI> uri = query->Uri();
     nsAutoCString uriSpec;
     nsresult rv = uri->GetSpec(uriSpec);
     NS_ENSURE_SUCCESS(rv, rv);
     nsAutoCString escaped;
     bool success = NS_Escape(uriSpec, escaped, url_XAlphas);
     NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
 
     AppendAmpersandIfNonempty(queryString);
     queryString.AppendLiteral(QUERYKEY_URI "=");
     queryString.Append(escaped);
   }
 
   // annotation
-  query->GetHasAnnotation(&hasIt);
-  if (hasIt) {
+  if (!query->Annotation().IsEmpty()) {
     AppendAmpersandIfNonempty(queryString);
-    bool annotationIsNot;
-    query->GetAnnotationIsNot(&annotationIsNot);
-    if (annotationIsNot)
+    if (query->AnnotationIsNot()) {
       queryString.AppendLiteral(QUERYKEY_NOTANNOTATION "=");
-    else
+    } else {
       queryString.AppendLiteral(QUERYKEY_ANNOTATION "=");
-    nsAutoCString annot;
-    query->GetAnnotation(annot);
+    }
+    const nsCString& annot = query->Annotation();
     nsAutoCString escaped;
     bool success = NS_Escape(annot, escaped, url_XAlphas);
     NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
     queryString.Append(escaped);
   }
 
   // folders
-  int64_t *folders = nullptr;
-  uint32_t folderCount = 0;
-  query->GetFolders(&folderCount, &folders);
-  for (uint32_t i = 0; i < folderCount; ++i) {
+  const nsTArray<int64_t>& folders = query->Folders();
+  for (uint32_t i = 0; i < folders.Length(); ++i) {
     AppendAmpersandIfNonempty(queryString);
     queryString += NS_LITERAL_CSTRING(QUERYKEY_FOLDER "=");
     nsresult rv = PlacesFolderConversion::AppendFolder(queryString, folders[i]);
     NS_ENSURE_SUCCESS(rv, rv);
   }
-  free(folders);
 
   // tags
-  const nsTArray<nsString> &tags = query->Tags();
+  const nsTArray<nsString>& tags = query->Tags();
   for (uint32_t i = 0; i < tags.Length(); ++i) {
     nsAutoCString escapedTag;
     if (!NS_Escape(NS_ConvertUTF16toUTF8(tags[i]), escapedTag, url_XAlphas))
       return NS_ERROR_OUT_OF_MEMORY;
 
     AppendAmpersandIfNonempty(queryString);
     queryString += NS_LITERAL_CSTRING(QUERYKEY_TAG "=");
     queryString += escapedTag;
--- a/toolkit/components/places/nsNavHistoryQuery.h
+++ b/toolkit/components/places/nsNavHistoryQuery.h
@@ -46,28 +46,25 @@ public:
   bool AnnotationIsNot() { return mAnnotationIsNot; }
   const nsCString& Annotation() { return mAnnotation; }
   const nsTArray<int64_t>& Folders() const { return mFolders; }
   const nsTArray<nsString>& Tags() const { return mTags; }
   nsresult SetTags(const nsTArray<nsString>& aTags)
   {
     if (!mTags.ReplaceElementsAt(0, mTags.Length(), aTags))
       return NS_ERROR_OUT_OF_MEMORY;
-
     return NS_OK;
   }
   bool TagsAreNot() { return mTagsAreNot; }
 
   const nsTArray<uint32_t>& Transitions() const { return mTransitions; }
   nsresult SetTransitions(const nsTArray<uint32_t>& aTransitions)
   {
-    if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(),
-                                        aTransitions))
+    if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), aTransitions))
       return NS_ERROR_OUT_OF_MEMORY;
-
     return NS_OK;
   }
 
   nsresult Clone(nsNavHistoryQuery **_clone);
 
 private:
   ~nsNavHistoryQuery() {}
 
--- a/toolkit/components/places/nsNavHistoryResult.cpp
+++ b/toolkit/components/places/nsNavHistoryResult.cpp
@@ -2342,19 +2342,17 @@ nsNavHistoryQueryResultNode::OnVisit(nsI
   switch(mLiveUpdate) {
     case QUERYUPDATE_MOBILEPREF: {
       return NS_OK;
     }
 
     case QUERYUPDATE_HOST: {
       // For these simple yet common cases we can check the host ourselves
       // before doing the overhead of creating a new result node.
-      bool hasDomain;
-      mQuery->GetHasDomain(&hasDomain);
-      if (!hasDomain)
+      if (mQuery->Domain().IsVoid())
         return NS_OK;
 
       nsAutoCString host;
       if (NS_FAILED(aURI->GetAsciiHost(host)))
         return NS_OK;
 
       if (!mQuery->Domain().Equals(host))
         return NS_OK;