mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-23 07:37:29 +09:00
Issue #2255 & #1240 - Simplify and enhance Maybe and Some(). https://bugzilla.mozilla.org/show_bug.cgi?id=1325351 This is a prerequisite for our BigInt V8 fast forward and potential #2255 fix.
This commit is contained in:
parent
81a3a92b04
commit
2c0384c4a2
2 changed files with 53 additions and 23 deletions
|
|
@ -588,6 +588,15 @@ class JS_FRIEND_API(AutoEnterPolicy)
|
||||||
inline void recordLeave() {}
|
inline void recordLeave() {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
// This operator needs to be deleted explicitly, otherwise Visual C++ will
|
||||||
|
// create it automatically when it is part of the export JS API. In that
|
||||||
|
// case, compile would fail because HandleId is not allowed to be assigned
|
||||||
|
// and consequently instantiation of assign operator of mozilla::Maybe
|
||||||
|
// would fail. See bug 1325351 comment 16. Copy constructor is removed at
|
||||||
|
// the same time for consistency.
|
||||||
|
AutoEnterPolicy(const AutoEnterPolicy&) = delete;
|
||||||
|
AutoEnterPolicy& operator=(const AutoEnterPolicy&) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef JS_DEBUG
|
#ifdef JS_DEBUG
|
||||||
|
|
|
||||||
67
mfbt/Maybe.h
67
mfbt/Maybe.h
|
|
@ -102,16 +102,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maybe<T*> can be copy-constructed from a Maybe<U*> if U* and T* are
|
* Maybe<T> can be copy-constructed from a Maybe<U> if U is convertible to T.
|
||||||
* compatible, or from Maybe<decltype(nullptr)>.
|
|
||||||
*/
|
*/
|
||||||
template<typename U,
|
template<typename U,
|
||||||
typename =
|
typename =
|
||||||
typename std::enable_if<std::is_pointer<T>::value &&
|
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||||
(std::is_same<U, decltype(nullptr)>::value ||
|
|
||||||
(std::is_pointer<U>::value &&
|
|
||||||
std::is_base_of<typename std::remove_pointer<T>::type,
|
|
||||||
typename std::remove_pointer<U>::type>::value))>::type>
|
|
||||||
MOZ_IMPLICIT
|
MOZ_IMPLICIT
|
||||||
Maybe(const Maybe<U>& aOther)
|
Maybe(const Maybe<U>& aOther)
|
||||||
: mIsSome(false)
|
: mIsSome(false)
|
||||||
|
|
@ -131,16 +126,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maybe<T*> can be move-constructed from a Maybe<U*> if U* and T* are
|
* Maybe<T> can be move-constructed from a Maybe<U> if U is convertible to T.
|
||||||
* compatible, or from Maybe<decltype(nullptr)>.
|
|
||||||
*/
|
*/
|
||||||
template<typename U,
|
template<typename U,
|
||||||
typename =
|
typename =
|
||||||
typename std::enable_if<std::is_pointer<T>::value &&
|
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||||
(std::is_same<U, decltype(nullptr)>::value ||
|
|
||||||
(std::is_pointer<U>::value &&
|
|
||||||
std::is_base_of<typename std::remove_pointer<T>::type,
|
|
||||||
typename std::remove_pointer<U>::type>::value))>::type>
|
|
||||||
MOZ_IMPLICIT
|
MOZ_IMPLICIT
|
||||||
Maybe(Maybe<U>&& aOther)
|
Maybe(Maybe<U>&& aOther)
|
||||||
: mIsSome(false)
|
: mIsSome(false)
|
||||||
|
|
@ -156,13 +146,7 @@ public:
|
||||||
if (&aOther != this) {
|
if (&aOther != this) {
|
||||||
if (aOther.mIsSome) {
|
if (aOther.mIsSome) {
|
||||||
if (mIsSome) {
|
if (mIsSome) {
|
||||||
// XXX(seth): The correct code for this branch, below, can't be used
|
|
||||||
// due to a bug in Visual Studio 2010. See bug 1052940.
|
|
||||||
/*
|
|
||||||
ref() = aOther.ref();
|
ref() = aOther.ref();
|
||||||
*/
|
|
||||||
reset();
|
|
||||||
emplace(*aOther);
|
|
||||||
} else {
|
} else {
|
||||||
emplace(*aOther);
|
emplace(*aOther);
|
||||||
}
|
}
|
||||||
|
|
@ -173,6 +157,23 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename U,
|
||||||
|
typename =
|
||||||
|
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||||
|
Maybe& operator=(const Maybe<U>& aOther)
|
||||||
|
{
|
||||||
|
if (aOther.isSome()) {
|
||||||
|
if (mIsSome) {
|
||||||
|
ref() = aOther.ref();
|
||||||
|
} else {
|
||||||
|
emplace(*aOther);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Maybe& operator=(Maybe&& aOther)
|
Maybe& operator=(Maybe&& aOther)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
||||||
|
|
@ -191,6 +192,25 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename U,
|
||||||
|
typename =
|
||||||
|
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||||
|
Maybe& operator=(Maybe<U>&& aOther)
|
||||||
|
{
|
||||||
|
if (aOther.isSome()) {
|
||||||
|
if (mIsSome) {
|
||||||
|
ref() = Move(aOther.ref());
|
||||||
|
} else {
|
||||||
|
emplace(Move(*aOther));
|
||||||
|
}
|
||||||
|
aOther.reset();
|
||||||
|
} else {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
/* Methods that check whether this Maybe contains a value */
|
/* Methods that check whether this Maybe contains a value */
|
||||||
explicit operator bool() const { return isSome(); }
|
explicit operator bool() const { return isSome(); }
|
||||||
bool isSome() const { return mIsSome; }
|
bool isSome() const { return mIsSome; }
|
||||||
|
|
@ -443,11 +463,12 @@ public:
|
||||||
* if you need to construct a Maybe value that holds a const, volatile, or
|
* if you need to construct a Maybe value that holds a const, volatile, or
|
||||||
* reference value, you need to use emplace() instead.
|
* reference value, you need to use emplace() instead.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T,
|
||||||
Maybe<typename RemoveCV<typename RemoveReference<T>::Type>::Type>
|
typename U = typename std::remove_cv<
|
||||||
|
typename std::remove_reference<T>::type>::type>
|
||||||
|
Maybe<U>
|
||||||
Some(T&& aValue)
|
Some(T&& aValue)
|
||||||
{
|
{
|
||||||
typedef typename RemoveCV<typename RemoveReference<T>::Type>::Type U;
|
|
||||||
Maybe<U> value;
|
Maybe<U> value;
|
||||||
value.emplace(Forward<T>(aValue));
|
value.emplace(Forward<T>(aValue));
|
||||||
return value;
|
return value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue