Bug 1551779 part 4. Stop using [array] for getItemAnnotationNames. r=mak
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 16 May 2019 14:54:15 +0000
changeset 474094 87a537f8e5a89204a95ec7395e9024688e16dfae
parent 474093 4c91b3e1fedeb142e9e79460b772c73902016392
child 474095 5db31f792bf4ee2c800edfc88d69e7d825ab3e44
push id36022
push userncsoregi@mozilla.com
push dateThu, 16 May 2019 21:55:16 +0000
treeherdermozilla-central@96802be91766 [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 4. Stop using [array] for getItemAnnotationNames. r=mak The old code used variants with SetAsAUTF8String, which would get converted to a string when going into JS. We can just use Array<AUTF8String> directly instead. C++ callers would need to change, but there aren't any. Differential Revision: https://phabricator.services.mozilla.com/D31241
toolkit/components/places/nsAnnotationService.cpp
toolkit/components/places/nsAnnotationService.h
toolkit/components/places/nsIAnnotationService.idl
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -334,19 +334,22 @@ nsAnnotationService::GetItemAnnotationIn
     *_storageType = nsIAnnotationService::TYPE_STRING;
   } else {
     *_storageType = type;
   }
 
   return GetValueFromStatement(statement, _value);
 }
 
-nsresult nsAnnotationService::GetItemAnnotationNamesTArray(
-    int64_t aItemId, nsTArray<nsCString>* _result) {
-  _result->Clear();
+NS_IMETHODIMP
+nsAnnotationService::GetItemAnnotationNames(int64_t aItemId,
+                                            nsTArray<nsCString>& _result) {
+  NS_ENSURE_ARG_MIN(aItemId, 1);
+
+  _result.Clear();
 
   nsCOMPtr<mozIStorageStatement> statement;
   statement = mDB->GetStatement(
       "SELECT n.name "
       "FROM moz_anno_attributes n "
       "JOIN moz_items_annos a ON a.anno_attribute_id = n.id "
       "WHERE a.item_id = :item_id");
   NS_ENSURE_STATE(statement);
@@ -356,54 +359,20 @@ nsresult nsAnnotationService::GetItemAnn
       statement->BindInt64ByName(NS_LITERAL_CSTRING("item_id"), aItemId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   bool hasResult = false;
   while (NS_SUCCEEDED(statement->ExecuteStep(&hasResult)) && hasResult) {
     nsAutoCString name;
     rv = statement->GetUTF8String(0, name);
     NS_ENSURE_SUCCESS(rv, rv);
-    if (!_result->AppendElement(name)) return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-nsAnnotationService::GetItemAnnotationNames(int64_t aItemId, uint32_t* _count,
-                                            nsIVariant*** _result) {
-  NS_ENSURE_ARG_MIN(aItemId, 1);
-  NS_ENSURE_ARG_POINTER(_count);
-  NS_ENSURE_ARG_POINTER(_result);
-
-  *_count = 0;
-  *_result = nullptr;
-
-  nsTArray<nsCString> names;
-  nsresult rv = GetItemAnnotationNamesTArray(aItemId, &names);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (names.Length() == 0) return NS_OK;
-
-  *_result = static_cast<nsIVariant**>(
-      moz_xmalloc(sizeof(nsIVariant*) * names.Length()));
-
-  for (uint32_t i = 0; i < names.Length(); i++) {
-    nsCOMPtr<nsIWritableVariant> var = new nsVariant();
-    if (!var) {
-      // need to release all the variants we've already created
-      for (uint32_t j = 0; j < i; j++) NS_RELEASE((*_result)[j]);
-      free(*_result);
-      *_result = nullptr;
+    if (!_result.AppendElement(name, fallible)) {
       return NS_ERROR_OUT_OF_MEMORY;
     }
-    var->SetAsAUTF8String(names[i]);
-    NS_ADDREF((*_result)[i] = var);
   }
-  *_count = names.Length();
 
   return NS_OK;
 }
 
 /**
  * @note We don't remove anything from the moz_anno_attributes table. If we
  *       delete the last item of a given name, that item really should go away.
  *       It will be cleaned up by expiration.
--- a/toolkit/components/places/nsAnnotationService.h
+++ b/toolkit/components/places/nsAnnotationService.h
@@ -101,14 +101,12 @@ class nsAnnotationService final : public
 
   nsresult RemoveAnnotationInternal(int64_t aItemId, BookmarkData* aBookmark,
                                     const nsACString& aName);
 
   nsresult GetValueFromStatement(nsCOMPtr<mozIStorageStatement>& aStatement,
                                  nsIVariant** _retval);
 
  public:
-  nsresult GetItemAnnotationNamesTArray(int64_t aItemId,
-                                        nsTArray<nsCString>* _result);
   nsresult RemoveItemAnnotations(int64_t aItemId);
 };
 
 #endif /* nsAnnotationService_h___ */
--- a/toolkit/components/places/nsIAnnotationService.idl
+++ b/toolkit/components/places/nsIAnnotationService.idl
@@ -98,25 +98,19 @@ interface nsIAnnotationService : nsISupp
     void getItemAnnotationInfo(in long long aItemId,
                                in AUTF8String aName,
                                out nsIVariant aValue,
                                out long aFlags,
                                out unsigned short aExpiration,
                                out unsigned short aType);
 
     /**
-     * Get the names of all annotations for this URI.
-     *
-     * example JS:
-     *   var annotations = annotator.getPageAnnotations(myURI, {});
+     * Get the names of all annotations for this item id.
      */
-    void getItemAnnotationNames(
-      in long long aItemId,
-      [optional] out unsigned long count,
-      [retval, array, size_is(count)] out nsIVariant result);
+    Array<AUTF8String> getItemAnnotationNames(in long long aItemId);
 
     /**
      * Test for annotation existence.
      */
     boolean itemHasAnnotation(in long long aItemId,
                               in AUTF8String aName);
 
     /**