Bug 1410186 - turn Maybe assertions into release assertions; r=bkelly

We out-of-line the relevant functions because release assertions can
generate quite a bit of code, and we'd rather let the compiler determine
if these functions should be inlined now.
This commit is contained in:
Nathan Froyd 2017-11-09 12:27:51 -05:00
parent dbb30b1c50
commit 37e5710099

View file

@ -225,11 +225,7 @@ public:
bool isNothing() const { return !mIsSome; }
/* Returns the contents of this Maybe<T> by value. Unsafe unless |isSome()|. */
T value() const
{
MOZ_ASSERT(mIsSome);
return ref();
}
T value() const;
/*
* Returns the contents of this Maybe<T> by value. If |isNothing()|, returns
@ -258,17 +254,8 @@ public:
}
/* Returns the contents of this Maybe<T> by pointer. Unsafe unless |isSome()|. */
T* ptr()
{
MOZ_ASSERT(mIsSome);
return &ref();
}
const T* ptr() const
{
MOZ_ASSERT(mIsSome);
return &ref();
}
T* ptr();
const T* ptr() const;
/*
* Returns the contents of this Maybe<T> by pointer. If |isNothing()|,
@ -312,30 +299,12 @@ public:
return aFunc();
}
T* operator->()
{
MOZ_ASSERT(mIsSome);
return ptr();
}
const T* operator->() const
{
MOZ_ASSERT(mIsSome);
return ptr();
}
T* operator->();
const T* operator->() const;
/* Returns the contents of this Maybe<T> by ref. Unsafe unless |isSome()|. */
T& ref()
{
MOZ_ASSERT(mIsSome);
return *static_cast<T*>(data());
}
const T& ref() const
{
MOZ_ASSERT(mIsSome);
return *static_cast<const T*>(data());
}
T& ref();
const T& ref() const;
/*
* Returns the contents of this Maybe<T> by ref. If |isNothing()|, returns
@ -379,17 +348,8 @@ public:
return aFunc();
}
T& operator*()
{
MOZ_ASSERT(mIsSome);
return ref();
}
const T& operator*() const
{
MOZ_ASSERT(mIsSome);
return ref();
}
T& operator*();
const T& operator*() const;
/* If |isSome()|, runs the provided function or functor on the contents of
* this Maybe. */
@ -453,12 +413,7 @@ public:
* arguments to |emplace()| are the parameters to T's constructor.
*/
template<typename... Args>
void emplace(Args&&... aArgs)
{
MOZ_ASSERT(!mIsSome);
::new (KnownNotNull, data()) T(Forward<Args>(aArgs)...);
mIsSome = true;
}
void emplace(Args&&... aArgs);
friend std::ostream&
operator<<(std::ostream& aStream, const Maybe<T>& aMaybe)
@ -472,6 +427,88 @@ public:
}
};
template<typename T>
T
Maybe<T>::value() const
{
MOZ_RELEASE_ASSERT(mIsSome);
return ref();
}
template<typename T>
T*
Maybe<T>::ptr()
{
MOZ_RELEASE_ASSERT(mIsSome);
return &ref();
}
template<typename T>
const T*
Maybe<T>::ptr() const
{
MOZ_RELEASE_ASSERT(mIsSome);
return &ref();
}
template<typename T>
T*
Maybe<T>::operator->()
{
MOZ_RELEASE_ASSERT(mIsSome);
return ptr();
}
template<typename T>
const T*
Maybe<T>::operator->() const
{
MOZ_RELEASE_ASSERT(mIsSome);
return ptr();
}
template<typename T>
T&
Maybe<T>::ref()
{
MOZ_RELEASE_ASSERT(mIsSome);
return *static_cast<T*>(data());
}
template<typename T>
const T&
Maybe<T>::ref() const
{
MOZ_RELEASE_ASSERT(mIsSome);
return *static_cast<const T*>(data());
}
template<typename T>
T&
Maybe<T>::operator*()
{
MOZ_RELEASE_ASSERT(mIsSome);
return ref();
}
template<typename T>
const T&
Maybe<T>::operator*() const
{
MOZ_RELEASE_ASSERT(mIsSome);
return ref();
}
template<typename T>
template<typename... Args>
void
Maybe<T>::emplace(Args&&... aArgs)
{
MOZ_RELEASE_ASSERT(!mIsSome);
::new (KnownNotNull, data()) T(Forward<Args>(aArgs)...);
mIsSome = true;
}
/*
* Some() creates a Maybe<T> value containing the provided T value. If T has a
* move constructor, it's used to make this as efficient as possible.