Bug 1551652. Stop using [array] in nsILayoutHistoryState. r=heycam
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 16 May 2019 00:36:41 +0000
changeset 535925 b7d724abf65e9a678c67016875b8acec25451f5b
parent 535924 79ca43bd514a81906b8ac0ec4c8fcbcdc80f4870
child 535926 1624c5a319174b9c850b3183a95d8bbefb051f41
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1551652
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 1551652. Stop using [array] in nsILayoutHistoryState. r=heycam I read through <https://searchfox.org/mozilla-central/search?q=%5B%5EA-Za-z_%5D%5BGg%5DetKeys%5B%5EA-Za-z_%5D&case=true&regexp=true&path=> and as far as I can tell the only JS consumer is SessionHistory.jsm, which was not passing the optional "count" arg already. There are no C++ consumers. Differential Revision: https://phabricator.services.mozilla.com/D31113
layout/base/nsILayoutHistoryState.idl
layout/base/nsLayoutHistoryState.cpp
--- a/layout/base/nsILayoutHistoryState.idl
+++ b/layout/base/nsILayoutHistoryState.idl
@@ -34,18 +34,17 @@ interface nsILayoutHistoryState : nsISup
   * Whether this LayoutHistoryState contains any PresStates.
   */
   readonly attribute boolean hasStates;
 
   /**
   * Get the keys of all PresStates held by this LayoutHistoryState.
   * Note: Check hasStates first.
   */
-  void getKeys([optional] out uint32_t aCount,
-               [array, size_is(aCount), retval] out string aKeys);
+  Array<ACString> getKeys();
 
   /*
   * Attempts to get the data of the PresState corresponding to
   * the passed key. Throws if no data could be found.
   */
   void getPresState(in ACString aKey,
                     out float aScrollX, out float aScrollY,
                     out boolean aAllowScrollOriginDowngrade,
--- a/layout/base/nsLayoutHistoryState.cpp
+++ b/layout/base/nsLayoutHistoryState.cpp
@@ -43,29 +43,24 @@ NS_IMPL_ISUPPORTS(nsLayoutHistoryState, 
 
 NS_IMETHODIMP
 nsLayoutHistoryState::GetHasStates(bool* aHasStates) {
   *aHasStates = HasStates();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsLayoutHistoryState::GetKeys(uint32_t* aCount, char*** aKeys) {
+nsLayoutHistoryState::GetKeys(nsTArray<nsCString>& aKeys) {
   if (!HasStates()) {
     return NS_ERROR_FAILURE;
   }
 
-  char** keys =
-      static_cast<char**>(moz_xmalloc(sizeof(char*) * mStates.Count()));
-  *aCount = mStates.Count();
-  *aKeys = keys;
-
+  aKeys.SetCapacity(mStates.Count());
   for (auto iter = mStates.Iter(); !iter.Done(); iter.Next()) {
-    *keys = ToNewCString(iter.Key());
-    keys++;
+    aKeys.AppendElement(iter.Key());
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsLayoutHistoryState::GetPresState(const nsACString& aKey, float* aScrollX,
                                    float* aScrollY,