Bug 819791 - Part 10: Don't return FallibletArrays by value in Variant.h. r=mak
authorJustin Lebar <justin.lebar@gmail.com>
Tue, 18 Dec 2012 20:16:07 -0500
changeset 125588 80ca371b52d5
parent 125587 fa47cd60942c
child 125589 1dfb85987ee0
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs819791
milestone20.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 819791 - Part 10: Don't return FallibletArrays by value in Variant.h. r=mak Returning *TArray's by value isn't compattible with explicit *TArray copy constructors, which will be added in a later cset.
storage/src/Variant.h
--- a/storage/src/Variant.h
+++ b/storage/src/Variant.h
@@ -54,49 +54,52 @@ struct variant_traits
   static inline uint16_t type() { return nsIDataType::VTYPE_EMPTY; }
 };
 
 template <typename DataType>
 struct variant_storage_traits
 {
   typedef DataType ConstructorType;
   typedef DataType StorageType;
-  static inline StorageType storage_conversion(ConstructorType aData) { return aData; }
+  static inline void storage_conversion(const ConstructorType aData, StorageType* _storage)
+  {
+    *_storage = aData;
+  }
 };
 
 #define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA;
 
 template <typename DataType>
 struct variant_integer_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
-  static inline nsresult asInt32(StorageType, int32_t *) { NO_CONVERSION }
-  static inline nsresult asInt64(StorageType, int64_t *) { NO_CONVERSION }
+  static inline nsresult asInt32(const StorageType &, int32_t *) { NO_CONVERSION }
+  static inline nsresult asInt64(const StorageType &, int64_t *) { NO_CONVERSION }
 };
 
 template <typename DataType>
 struct variant_float_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
-  static inline nsresult asDouble(StorageType, double *) { NO_CONVERSION }
+  static inline nsresult asDouble(const StorageType &, double *) { NO_CONVERSION }
 };
 
 template <typename DataType>
 struct variant_text_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
-  static inline nsresult asUTF8String(StorageType, nsACString &) { NO_CONVERSION }
-  static inline nsresult asString(StorageType, nsAString &) { NO_CONVERSION }
+  static inline nsresult asUTF8String(const StorageType &, nsACString &) { NO_CONVERSION }
+  static inline nsresult asString(const StorageType &, nsAString &) { NO_CONVERSION }
 };
 
 template <typename DataType>
 struct variant_blob_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
-  static inline nsresult asArray(StorageType, uint16_t *, uint32_t *, void **)
+  static inline nsresult asArray(const StorageType &, uint16_t *, uint32_t *, void **)
   { NO_CONVERSION }
 };
 
 #undef NO_CONVERSION
 
 /**
  * INTEGER types
  */
@@ -166,19 +169,19 @@ struct variant_traits<nsString>
 {
   static inline uint16_t type() { return nsIDataType::VTYPE_ASTRING; }
 };
 template < >
 struct variant_storage_traits<nsString>
 {
   typedef const nsAString & ConstructorType;
   typedef nsString StorageType;
-  static inline StorageType storage_conversion(ConstructorType aText)
+  static inline void storage_conversion(ConstructorType aText, StorageType* _outData)
   {
-    return StorageType(aText);
+    *_outData = aText;
   }
 };
 template < >
 struct variant_text_traits<nsString>
 {
   static inline nsresult asUTF8String(const nsString &aValue,
                                       nsACString &_result)
   {
@@ -198,19 +201,19 @@ struct variant_traits<nsCString>
 {
   static inline uint16_t type() { return nsIDataType::VTYPE_UTF8STRING; }
 };
 template < >
 struct variant_storage_traits<nsCString>
 {
   typedef const nsACString & ConstructorType;
   typedef nsCString StorageType;
-  static inline StorageType storage_conversion(ConstructorType aText)
+  static inline void storage_conversion(ConstructorType aText, StorageType* _outData)
   {
-    return StorageType(aText);
+    *_outData = aText;
   }
 };
 template < >
 struct variant_text_traits<nsCString>
 {
   static inline nsresult asUTF8String(const nsCString &aValue,
                                       nsACString &_result)
   {
@@ -234,22 +237,22 @@ struct variant_traits<uint8_t[]>
 {
   static inline uint16_t type() { return nsIDataType::VTYPE_ARRAY; }
 };
 template < >
 struct variant_storage_traits<uint8_t[]>
 {
   typedef std::pair<const void *, int> ConstructorType;
   typedef FallibleTArray<uint8_t> StorageType;
-  static inline StorageType storage_conversion(ConstructorType aBlob)
+  static inline void storage_conversion(ConstructorType aBlob, StorageType* _outData)
   {
-    StorageType data(aBlob.second);
-    (void)data.AppendElements(static_cast<const uint8_t *>(aBlob.first),
-                              aBlob.second);
-    return data;
+    _outData->Clear();
+    _outData->SetCapacity(aBlob.second);
+    (void)_outData->AppendElements(static_cast<const uint8_t *>(aBlob.first),
+                                   aBlob.second);
   }
 };
 template < >
 struct variant_blob_traits<uint8_t[]>
 {
   static inline nsresult asArray(FallibleTArray<uint8_t> &aData,
                                  uint16_t *_type,
                                  uint32_t *_size,
@@ -307,19 +310,19 @@ public:
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Template Implementation
 
 template <typename DataType>
 class Variant : public Variant_base
 {
 public:
-  Variant(typename variant_storage_traits<DataType>::ConstructorType aData)
-    : mData(variant_storage_traits<DataType>::storage_conversion(aData))
+  Variant(const typename variant_storage_traits<DataType>::ConstructorType& aData)
   {
+    variant_storage_traits<DataType>::storage_conversion(aData, &mData);
   }
 
   NS_IMETHOD GetDataType(uint16_t *_type)
   {
     *_type = variant_traits<DataType>::type();
     return NS_OK;
   }
   NS_IMETHOD GetAsInt32(int32_t *_integer)