Bug 1563065: Use const& in mozilla::Result constructors. r=froydnj
authorJim Blandy <jimb@mozilla.com>
Fri, 05 Jul 2019 23:50:16 +0000
changeset 541181 921eab31ab8eaa9c381d5c44b65fc2045c97845a
parent 541180 60f79580d32789527c021173d2c706183e568e9d
child 541182 91d8f385c5e5ec15c5cdb1d6c24b582fe1862acc
push id11533
push userarchaeopteryx@coole-files.de
push dateMon, 08 Jul 2019 18:18:03 +0000
treeherdermozilla-beta@f4452e031aed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1563065
milestone69.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 1563065: Use const& in mozilla::Result constructors. r=froydnj Change the `ResultImplementation` and `Result` constructors to accept success values by `const` reference. This makes it possible for `Result` to carry `MOZ_NON_PARAM` types as success values. Differential Revision: https://phabricator.services.mozilla.com/D36682
mfbt/Result.h
--- a/mfbt/Result.h
+++ b/mfbt/Result.h
@@ -42,17 +42,17 @@ enum class PackingStrategy {
 template <typename V, typename E, PackingStrategy Strategy>
 class ResultImplementation;
 
 template <typename V, typename E>
 class ResultImplementation<V, E, PackingStrategy::Variant> {
   mozilla::Variant<V, E> mStorage;
 
  public:
-  explicit ResultImplementation(V aValue) : mStorage(aValue) {}
+  explicit ResultImplementation(const V& aValue) : mStorage(aValue) {}
   explicit ResultImplementation(E aErrorValue) : mStorage(aErrorValue) {}
 
   bool isOk() const { return mStorage.template is<V>(); }
 
   // The callers of these functions will assert isOk() has the proper value, so
   // these functions (in all ResultImplementation specializations) don't need
   // to do so.
   V unwrap() const { return mStorage.template as<V>(); }
@@ -63,17 +63,17 @@ class ResultImplementation<V, E, Packing
  * mozilla::Variant doesn't like storing a reference. This is a specialization
  * to store E as pointer if it's a reference.
  */
 template <typename V, typename E>
 class ResultImplementation<V, E&, PackingStrategy::Variant> {
   mozilla::Variant<V, E*> mStorage;
 
  public:
-  explicit ResultImplementation(V aValue) : mStorage(aValue) {}
+  explicit ResultImplementation(const V& aValue) : mStorage(aValue) {}
   explicit ResultImplementation(E& aErrorValue) : mStorage(&aErrorValue) {}
 
   bool isOk() const { return mStorage.template is<V>(); }
   V unwrap() const { return mStorage.template as<V>(); }
   E& unwrapErr() const { return *mStorage.template as<E*>(); }
 };
 
 /**
@@ -295,17 +295,17 @@ class MOZ_MUST_USE_TYPE Result final {
   using Impl = typename detail::SelectResultImpl<V, E>::Type;
 
   Impl mImpl;
 
  public:
   /**
    * Create a success result.
    */
-  MOZ_IMPLICIT Result(V aValue) : mImpl(aValue) { MOZ_ASSERT(isOk()); }
+  MOZ_IMPLICIT Result(const V& aValue) : mImpl(aValue) { MOZ_ASSERT(isOk()); }
 
   /**
    * Create an error result.
    */
   explicit Result(E aErrorValue) : mImpl(aErrorValue) { MOZ_ASSERT(isErr()); }
 
   /**
    * Implementation detail of MOZ_TRY().