Bug 1551647. Stop using [array] in nsIProperties. r=froydnj
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 14 May 2019 18:46:13 +0000
changeset 535703 1b7aa4ccb45fed7631a62bace49cd6da0ac7d32b
parent 535702 5df94e4b78cc5fcb8a1cf8f5664b256c346f2f21
child 535704 22dba7347176f6885c4ee3f978aa13a35fc7862e
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)
reviewersfroydnj
bugs1551647
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 1551647. Stop using [array] in nsIProperties. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D31110
image/RasterImage.cpp
xpcom/ds/nsIProperties.idl
xpcom/ds/nsPersistentProperties.cpp
xpcom/ds/nsProperties.cpp
xpcom/io/nsDirectoryService.cpp
--- a/image/RasterImage.cpp
+++ b/image/RasterImage.cpp
@@ -1004,23 +1004,22 @@ NS_IMETHODIMP
 RasterImage::Undefine(const char* prop) {
   if (!mProperties) {
     return NS_ERROR_FAILURE;
   }
   return mProperties->Undefine(prop);
 }
 
 NS_IMETHODIMP
-RasterImage::GetKeys(uint32_t* count, char*** keys) {
+RasterImage::GetKeys(nsTArray<nsCString>& keys) {
   if (!mProperties) {
-    *count = 0;
-    *keys = nullptr;
+    keys.Clear();
     return NS_OK;
   }
-  return mProperties->GetKeys(count, keys);
+  return mProperties->GetKeys(keys);
 }
 
 void RasterImage::Discard() {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(CanDiscard(), "Asked to discard but can't");
   MOZ_ASSERT(!mAnimationState || gfxPrefs::ImageMemAnimatedDiscardable(),
              "Asked to discard for animated image");
 
--- a/xpcom/ds/nsIProperties.idl
+++ b/xpcom/ds/nsIProperties.idl
@@ -37,10 +37,10 @@ interface nsIProperties : nsISupports
      * @throws NS_ERROR_FAILURE if a property with that name doesn't
      * already exist.
      */
     void undefine(in string prop);
 
     /**
      *  Returns an array of the keys.
      */
-    void getKeys(out uint32_t count, [array, size_is(count), retval] out string keys);
+    Array<ACString> getKeys();
 };
--- a/xpcom/ds/nsPersistentProperties.cpp
+++ b/xpcom/ds/nsPersistentProperties.cpp
@@ -538,17 +538,17 @@ nsPersistentProperties::Undefine(const c
 
 NS_IMETHODIMP
 nsPersistentProperties::Has(const char* aProp, bool* aResult) {
   *aResult = !!mTable.Search(aProp);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsPersistentProperties::GetKeys(uint32_t* aCount, char*** aKeys) {
+nsPersistentProperties::GetKeys(nsTArray<nsCString>& aKeys) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // PropertyElement
 ////////////////////////////////////////////////////////////////////////////////
 
 nsresult nsPropertyElement::Create(nsISupports* aOuter, REFNSIID aIID,
--- a/xpcom/ds/nsProperties.cpp
+++ b/xpcom/ds/nsProperties.cpp
@@ -47,38 +47,20 @@ nsProperties::Has(const char* prop, bool
     return NS_ERROR_INVALID_ARG;
   }
 
   *result = nsProperties_HashBase::Contains(prop);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsProperties::GetKeys(uint32_t* aCount, char*** aKeys) {
-  if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
+nsProperties::GetKeys(nsTArray<nsCString>& aKeys) {
   uint32_t count = Count();
-  char** keys = (char**)moz_xmalloc(count * sizeof(char*));
-  uint32_t j = 0;
+  aKeys.SetCapacity(count);
 
   for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
-    const char* key = iter.Key();
-    keys[j] = strdup(key);
-
-    if (!keys[j]) {
-      // Free 'em all
-      for (uint32_t i = 0; i < j; i++) {
-        free(keys[i]);
-      }
-      free(keys);
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-    j++;
+    aKeys.AppendElement(iter.Key());
   }
 
-  *aCount = count;
-  *aKeys = keys;
   return NS_OK;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
--- a/xpcom/io/nsDirectoryService.cpp
+++ b/xpcom/io/nsDirectoryService.cpp
@@ -117,17 +117,17 @@ nsDirectoryService::Undefine(const char*
     return NS_ERROR_INVALID_ARG;
   }
 
   nsDependentCString key(aProp);
   return mHashtable.Remove(key) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
-nsDirectoryService::GetKeys(uint32_t* aCount, char*** aKeys) {
+nsDirectoryService::GetKeys(nsTArray<nsCString>& aKeys) {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 struct MOZ_STACK_CLASS FileData {
   FileData(const char* aProperty, const nsIID& aUUID)
       : property(aProperty), data(nullptr), persistent(true), uuid(aUUID) {}
 
   const char* property;