Bug 1585585 - Add {MOZ_LIKELY,MOZ_UNLIKELY} to Result::{isOk,isErr} consumers. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D48136

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tooru Fujisawa 2019-10-10 23:46:42 +00:00
Родитель 6ca3ab075b
Коммит afa6435815
1 изменённых файлов: 8 добавлений и 5 удалений

Просмотреть файл

@ -386,7 +386,9 @@ class MOZ_MUST_USE_TYPE Result final {
* Take the success value from this Result, which must be a success result.
* If it is an error result, then return the aValue.
*/
V unwrapOr(V aValue) { return isOk() ? mImpl.unwrap() : std::move(aValue); }
V unwrapOr(V aValue) {
return MOZ_LIKELY(isOk()) ? mImpl.unwrap() : std::move(aValue);
}
/** Take the error value from this Result, which must be an error result. */
E unwrapErr() {
@ -431,7 +433,7 @@ class MOZ_MUST_USE_TYPE Result final {
template <typename F>
auto map(F f) -> Result<decltype(f(*((V*)nullptr))), E> {
using RetResult = Result<decltype(f(*((V*)nullptr))), E>;
return isOk() ? RetResult(f(unwrap())) : RetResult(unwrapErr());
return MOZ_LIKELY(isOk()) ? RetResult(f(unwrap())) : RetResult(unwrapErr());
}
/**
@ -496,7 +498,8 @@ class MOZ_MUST_USE_TYPE Result final {
template <typename F, typename = typename EnableIf<detail::IsResult<decltype(
(*((F*)nullptr))(*((V*)nullptr)))>::value>::Type>
auto andThen(F f) -> decltype(f(*((V*)nullptr))) {
return isOk() ? f(unwrap()) : GenericErrorResult<E>(unwrapErr());
return MOZ_LIKELY(isOk()) ? f(unwrap())
: GenericErrorResult<E>(unwrapErr());
}
};
@ -534,7 +537,7 @@ inline GenericErrorResult<E> Err(E&& aErrorValue) {
#define MOZ_TRY(expr) \
do { \
auto mozTryTempResult_ = ::mozilla::ToResult(expr); \
if (mozTryTempResult_.isErr()) { \
if (MOZ_UNLIKELY(mozTryTempResult_.isErr())) { \
return ::mozilla::Err(mozTryTempResult_.unwrapErr()); \
} \
} while (0)
@ -549,7 +552,7 @@ inline GenericErrorResult<E> Err(E&& aErrorValue) {
#define MOZ_TRY_VAR(target, expr) \
do { \
auto mozTryVarTempResult_ = (expr); \
if (mozTryVarTempResult_.isErr()) { \
if (MOZ_UNLIKELY(mozTryVarTempResult_.isErr())) { \
return ::mozilla::Err(mozTryVarTempResult_.unwrapErr()); \
} \
(target) = mozTryVarTempResult_.unwrap(); \