Bug 1497831 - Use nsTArray instead of nsIArray for nsIFormatConverter. r=smaug
authorTom Schuster <evilpies@gmail.com>
Wed, 10 Oct 2018 20:26:06 +0000
changeset 440645 55588bdd2ee8f5bcd66c6af0b340d5b02bf0411e
parent 440644 2852663b840e9a4348130dcbf8efdd494f738a76
child 440646 9a802bdfec41c901a97985088fdfe2867cd41cb0
push id108828
push usertoros@mozilla.com
push dateThu, 11 Oct 2018 04:01:39 +0000
treeherdermozilla-inbound@e4220fa7a191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1497831
milestone64.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 1497831 - Use nsTArray instead of nsIArray for nsIFormatConverter. r=smaug Depends on D8194 Differential Revision: https://phabricator.services.mozilla.com/D8195
widget/nsHTMLFormatConverter.cpp
widget/nsHTMLFormatConverter.h
widget/nsIFormatConverter.idl
widget/nsTransferable.cpp
--- a/widget/nsHTMLFormatConverter.cpp
+++ b/widget/nsHTMLFormatConverter.cpp
@@ -30,88 +30,38 @@ nsHTMLFormatConverter::~nsHTMLFormatConv
 NS_IMPL_ISUPPORTS(nsHTMLFormatConverter, nsIFormatConverter)
 
 //
 // GetInputDataFlavors
 //
 // Creates a new list and returns the list of all the flavors this converter
 // knows how to import. In this case, it's just HTML.
 //
-// Flavors (strings) are wrapped in a primitive object so that JavaScript can
-// access them easily via XPConnect.
-//
 NS_IMETHODIMP
-nsHTMLFormatConverter::GetInputDataFlavors(nsIArray **_retval)
+nsHTMLFormatConverter::GetInputDataFlavors(nsTArray<nsCString>& aFlavors)
 {
-  if ( !_retval )
-    return NS_ERROR_INVALID_ARG;
-
-  nsCOMPtr<nsIMutableArray> array = nsArray::Create();
-  nsresult rv = AddFlavorToList ( array, kHTMLMime );
-
-  array.forget(_retval);
-  return rv;
-
-} // GetInputDataFlavors
+  aFlavors.AppendElement(NS_LITERAL_CSTRING(kHTMLMime));
+  return NS_OK;
+}
 
 
 //
 // GetOutputDataFlavors
 //
 // Creates a new list and returns the list of all the flavors this converter
 // knows how to export (convert). In this case, it's all sorts of things that HTML can be
 // converted to.
 //
-// Flavors (strings) are wrapped in a primitive object so that JavaScript can
-// access them easily via XPConnect.
-//
 NS_IMETHODIMP
-nsHTMLFormatConverter::GetOutputDataFlavors(nsIArray **_retval)
+nsHTMLFormatConverter::GetOutputDataFlavors(nsTArray<nsCString>& aFlavors)
 {
-  if ( !_retval )
-    return NS_ERROR_INVALID_ARG;
-
-  nsCOMPtr<nsIMutableArray> array = nsArray::Create();
-  nsresult rv = AddFlavorToList ( array, kHTMLMime );
-  if ( NS_FAILED(rv) )
-    return rv;
-  rv = AddFlavorToList ( array, kUnicodeMime );
-  if ( NS_FAILED(rv) )
-    return rv;
-
-  array.forget(_retval);
-  return rv;
-
-} // GetOutputDataFlavors
-
-
-//
-// AddFlavorToList
-//
-// Convenience routine for adding a flavor wrapped in an nsISupportsCString object
-// to a list
-//
-nsresult
-nsHTMLFormatConverter :: AddFlavorToList ( nsCOMPtr<nsIMutableArray>& inList, const char* inFlavor )
-{
-  nsresult rv;
-
-  nsCOMPtr<nsISupportsCString> dataFlavor =
-      do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
-  if ( dataFlavor ) {
-    dataFlavor->SetData ( nsDependentCString(inFlavor) );
-    // add to list as an nsISupports so the correct interface gets the addref
-    // in AppendElement()
-    nsCOMPtr<nsISupports> genericFlavor ( do_QueryInterface(dataFlavor) );
-    inList->AppendElement ( genericFlavor );
-  }
-  return rv;
-
-} // AddFlavorToList
-
+  aFlavors.AppendElement(NS_LITERAL_CSTRING(kHTMLMime));
+  aFlavors.AppendElement(NS_LITERAL_CSTRING(kUnicodeMime));
+  return NS_OK;
+}
 
 //
 // CanConvert
 //
 // Determines if we support the given conversion. Currently, this method only
 // converts from HTML to others.
 //
 NS_IMETHODIMP
--- a/widget/nsHTMLFormatConverter.h
+++ b/widget/nsHTMLFormatConverter.h
@@ -20,16 +20,14 @@ public:
 
   // nsISupports
   NS_DECL_ISUPPORTS
   NS_DECL_NSIFORMATCONVERTER
 
 protected:
   virtual ~nsHTMLFormatConverter();
 
-  nsresult AddFlavorToList ( nsCOMPtr<nsIMutableArray>& inList, const char* inFlavor ) ;
-
   NS_IMETHOD ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr);
   NS_IMETHOD ConvertFromHTMLToAOLMail(const nsAutoString & aFromStr, nsAutoString & aToStr);
 
 };
 
 #endif // nsHTMLFormatConverter_h__
--- a/widget/nsIFormatConverter.idl
+++ b/widget/nsIFormatConverter.idl
@@ -1,35 +1,33 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
-#include "nsIArray.idl"
-
 
 [scriptable, uuid(948A0023-E3A7-11d2-96CF-0060B0FB9956)]
 interface nsIFormatConverter : nsISupports
 {  
   /**
     * Get the list of the "input" data flavors (mime types as nsISupportsCString),
     * in otherwords, the flavors that this converter can convert "from" (the 
     * incoming data to the converter).
     */
-  nsIArray getInputDataFlavors ( ) ;
+  Array<ACString> getInputDataFlavors ( ) ;
 
   /**
     * Get the list of the "output" data flavors (mime types as nsISupportsCString),
     * in otherwords, the flavors that this converter can convert "to" (the 
     * outgoing data to the converter).
     *
     * @param  aDataFlavorList fills list with supported flavors
     */
-  nsIArray getOutputDataFlavors ( ) ;
+  Array<ACString> getOutputDataFlavors ( ) ;
 
   /**
     * Determines whether a conversion from one flavor to another is supported
     *
     * @param  aFromFormatConverter flavor to convert from
     * @param  aFromFormatConverter flavor to convert to
     */
   boolean canConvert ( in string aFromDataFlavor, in string aToDataFlavor ) ;
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -495,33 +495,25 @@ nsTransferable::FlavorsTransferableCanIm
   MOZ_ASSERT(mInitialized);
 
   // Get the flavor list, and on to the end of it, append the list of flavors we
   // can also get to through a converter. This is so that we can just walk the list
   // in one go, looking for the desired flavor.
   GetTransferDataFlavors(aFlavors);
 
   if (mFormatConv) {
-    nsCOMPtr<nsIArray> convertedList;
-    mFormatConv->GetInputDataFlavors(getter_AddRefs(convertedList));
-
-    if ( convertedList ) {
-      uint32_t importListLen;
-      convertedList->GetLength(&importListLen);
+    nsTArray<nsCString> convertedList;
+    mFormatConv->GetInputDataFlavors(convertedList);
 
-      for (uint32_t i = 0; i < importListLen; ++i ) {
-        nsCOMPtr<nsISupportsCString> flavorWrapper =
-            do_QueryElementAt(convertedList, i);
-        nsAutoCString flavorStr;
-        flavorWrapper->GetData( flavorStr );
+    for (uint32_t i = 0; i < convertedList.Length(); ++i) {
+      nsCString& flavorStr = convertedList[i];
 
-        // Don't append if already in intrinsic list
-        if (!aFlavors.Contains(flavorStr)) {
-          aFlavors.AppendElement(flavorStr);
-        }
+      // Don't append if already in intrinsic list
+      if (!aFlavors.Contains(flavorStr)) {
+        aFlavors.AppendElement(flavorStr);
       }
     }
   }
 
   return NS_OK;
 }
 
 
@@ -538,33 +530,25 @@ nsTransferable::FlavorsTransferableCanEx
 
 
   // Get the flavor list, and on to the end of it, append the list of flavors we
   // can also get to through a converter. This is so that we can just walk the list
   // in one go, looking for the desired flavor.
   GetTransferDataFlavors(aFlavors);
 
   if (mFormatConv) {
-    nsCOMPtr<nsIArray> convertedList;
-    mFormatConv->GetOutputDataFlavors(getter_AddRefs(convertedList));
-
-    if ( convertedList ) {
-      uint32_t importListLen;
-      convertedList->GetLength(&importListLen);
+    nsTArray<nsCString> convertedList;
+    mFormatConv->GetOutputDataFlavors(convertedList);
 
-      for ( uint32_t i=0; i < importListLen; ++i ) {
-        nsCOMPtr<nsISupportsCString> flavorWrapper =
-            do_QueryElementAt(convertedList, i);
-        nsAutoCString flavorStr;
-        flavorWrapper->GetData( flavorStr );
+    for (uint32_t i = 0; i < convertedList.Length(); ++i) {
+      nsCString& flavorStr = convertedList[i];
 
-        // Don't append if already in intrinsic list
-        if (!aFlavors.Contains(flavorStr)) {
-          aFlavors.AppendElement(flavorStr);
-        }
+      // Don't append if already in intrinsic list
+      if (!aFlavors.Contains(flavorStr)) {
+        aFlavors.AppendElement(flavorStr);
       }
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP