Bug 1551779 part 1. Stop using [array] for get/setTransitions in nsINavHistoryService. r=mak
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 16 May 2019 12:19:49 +0000
changeset 532933 722c158c53865db371646a40084e26a8dd788ea3
parent 532932 0aba6e58bd624af9a96356dc7d49f259c6adea43
child 532934 f5db7f234584c20947fc4fa592b1263d1582df0b
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1551779
milestone68.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 1551779 part 1. Stop using [array] for get/setTransitions in nsINavHistoryService. r=mak Differential Revision: https://phabricator.services.mozilla.com/D31237
toolkit/components/places/nsINavHistoryService.idl
toolkit/components/places/nsNavHistoryQuery.cpp
toolkit/components/places/nsNavHistoryQuery.h
toolkit/components/places/tests/queries/test_downloadHistory_liveUpdate.js
toolkit/components/places/tests/queries/test_querySerialization.js
--- a/toolkit/components/places/nsINavHistoryService.idl
+++ b/toolkit/components/places/nsINavHistoryService.idl
@@ -789,24 +789,22 @@ interface nsINavHistoryQuery : nsISuppor
 
   /**
    * When the set of transitions is nonempty, results are limited to pages which
    * have at least one visit for each of the transition types.
    * @note: For searching on more than one transition this can be very slow.
    *
    * Limit results to the specified list of transition types.
    */
-  void setTransitions([const,array, size_is(count)] in unsigned long transitions,
-                      in unsigned long count);
+  void setTransitions(in Array<unsigned long> transitions);
 
   /**
    * Get the transitions set for this query.
    */
-  void getTransitions([optional] out unsigned long count,
-                      [retval,array,size_is(count)] out unsigned long transitions);
+  Array<unsigned long> getTransitions();
 
   /**
    * Get the count of the set query transitions.
    */
   readonly attribute unsigned long transitionCount;
 
   /**
    * When set, returns only bookmarked items, when unset, returns anything. Setting this
--- a/toolkit/components/places/nsNavHistoryQuery.cpp
+++ b/toolkit/components/places/nsNavHistoryQuery.cpp
@@ -906,43 +906,32 @@ NS_IMETHODIMP nsNavHistoryQuery::SetPare
     if (!mParents.AppendElement(aGuids[i])) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNavHistoryQuery::GetTransitions(uint32_t* aCount,
-                                                uint32_t** aTransitions) {
-  uint32_t count = mTransitions.Length();
-  uint32_t* transitions = nullptr;
-  if (count > 0) {
-    transitions =
-        reinterpret_cast<uint32_t*>(moz_xmalloc(count * sizeof(uint32_t)));
-    for (uint32_t i = 0; i < count; ++i) {
-      transitions[i] = mTransitions[i];
-    }
-  }
-  *aCount = count;
-  *aTransitions = transitions;
+NS_IMETHODIMP nsNavHistoryQuery::GetTransitions(
+    nsTArray<uint32_t>& aTransitions) {
+  aTransitions = mTransitions;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsNavHistoryQuery::GetTransitionCount(uint32_t* aCount) {
   *aCount = mTransitions.Length();
   return NS_OK;
 }
 
-NS_IMETHODIMP nsNavHistoryQuery::SetTransitions(const uint32_t* aTransitions,
-                                                uint32_t aCount) {
-  if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), aTransitions,
-                                      aCount))
+NS_IMETHODIMP nsNavHistoryQuery::SetTransitions(
+    const nsTArray<uint32_t>& aTransitions) {
+  if (!mTransitions.Assign(aTransitions, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
-
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNavHistoryQuery::Clone(nsINavHistoryQuery** _clone) {
   nsNavHistoryQuery* clone = nullptr;
   Unused << Clone(&clone);
   *_clone = clone;
--- a/toolkit/components/places/nsNavHistoryQuery.h
+++ b/toolkit/components/places/nsNavHistoryQuery.h
@@ -59,21 +59,16 @@ class nsNavHistoryQuery final : public n
   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))
-      return NS_ERROR_OUT_OF_MEMORY;
-    return NS_OK;
-  }
 
   nsresult Clone(nsNavHistoryQuery** _clone);
 
  private:
   ~nsNavHistoryQuery() {}
 
  protected:
   // IF YOU ADD MORE ITEMS:
--- a/toolkit/components/places/tests/queries/test_downloadHistory_liveUpdate.js
+++ b/toolkit/components/places/tests/queries/test_downloadHistory_liveUpdate.js
@@ -23,17 +23,17 @@ function accumulateNotifications(result)
   });
   result.addObserver(resultObserver, false);
   return resultObserver;
 }
 
 add_task(async function test_downloadhistory_query_notifications() {
   const MAX_RESULTS = 5;
   let query = PlacesUtils.history.getNewQuery();
-  query.setTransitions([PlacesUtils.history.TRANSITIONS.DOWNLOAD], 1);
+  query.setTransitions([PlacesUtils.history.TRANSITIONS.DOWNLOAD]);
   let options = PlacesUtils.history.getNewQueryOptions();
   options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
   options.maxResults = MAX_RESULTS;
   let result = PlacesUtils.history.executeQuery(query, options);
   let notifications = accumulateNotifications(result);
   let root = PlacesUtils.asContainer(result.root);
   root.containerOpen = true;
   // Add more maxResults downloads in order.
@@ -69,17 +69,17 @@ add_task(async function test_downloadhis
                        "nodeTitleChanged",
                        "nodeIconChanged",
                        "nodeRemoved"]);
 });
 
 add_task(async function test_downloadhistory_query_filtering() {
   const MAX_RESULTS = 3;
   let query = PlacesUtils.history.getNewQuery();
-  query.setTransitions([PlacesUtils.history.TRANSITIONS.DOWNLOAD], 1);
+  query.setTransitions([PlacesUtils.history.TRANSITIONS.DOWNLOAD]);
   let options = PlacesUtils.history.getNewQueryOptions();
   options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING;
   options.maxResults = MAX_RESULTS;
   let result = PlacesUtils.history.executeQuery(query, options);
   let root = PlacesUtils.asContainer(result.root);
   root.containerOpen = true;
   Assert.equal(root.childCount, 0, "No visits found");
   // Add more than maxResults downloads.
--- a/toolkit/components/places/tests/queries/test_querySerialization.js
+++ b/toolkit/components/places/tests/queries/test_querySerialization.js
@@ -313,25 +313,24 @@ const querySwitches = [
       for (let i = 0; i < q2Trans.length; i++) {
         if (!q1Trans.includes(q2Trans[i]))
           return false;
       }
       return true;
     },
     runs: [
       function(aQuery, aQueryOptions) {
-        aQuery.setTransitions([], 0);
+        aQuery.setTransitions([]);
       },
       function(aQuery, aQueryOptions) {
-        aQuery.setTransitions([Ci.nsINavHistoryService.TRANSITION_DOWNLOAD],
-                              1);
+        aQuery.setTransitions([Ci.nsINavHistoryService.TRANSITION_DOWNLOAD]);
       },
       function(aQuery, aQueryOptions) {
         aQuery.setTransitions([Ci.nsINavHistoryService.TRANSITION_TYPED,
-                               Ci.nsINavHistoryService.TRANSITION_BOOKMARK], 2);
+                               Ci.nsINavHistoryService.TRANSITION_BOOKMARK]);
       },
     ],
   },
 ];
 
 // nsINavHistoryQueryOptions switches
 const queryOptionSwitches = [
   // sortingMode