Bug 1585519 - Part 3: Add MOZ_UNLIKELY to error handling macro. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Mon, 07 Oct 2019 05:11:31 +0000
changeset 496466 e8cbe45ac45286ea9e45343e7e9c324f0af33906
parent 496465 d34594143118bcfd489a5a13de958e8e24ad62ab
child 496467 ab13ef2740e0c6c59e7db54a6604dde817320102
push id36659
push userrgurzau@mozilla.com
push dateMon, 07 Oct 2019 09:29:54 +0000
treeherdermozilla-central@3955e0a93047 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1585519
milestone71.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 1585519 - Part 3: Add MOZ_UNLIKELY to error handling macro. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D48015
js/src/frontend/BinAST-macros.h
--- a/js/src/frontend/BinAST-macros.h
+++ b/js/src/frontend/BinAST-macros.h
@@ -7,56 +7,67 @@
 #ifndef frontend_BinAST_macros_h
 #define frontend_BinAST_macros_h
 
 #include "vm/JSContext.h"
 
 // Evaluate an expression EXPR, checking that the result is not falsy.
 //
 // Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
-#define BINJS_TRY(EXPR)                            \
-  do {                                             \
-    if (!EXPR) return cx_->alreadyReportedError(); \
+#define BINJS_TRY(EXPR)                   \
+  do {                                    \
+    if (MOZ_UNLIKELY(!(EXPR))) {          \
+      return cx_->alreadyReportedError(); \
+    }                                     \
   } while (false)
 
 // Evaluate an expression EXPR, checking that the result is not falsy.
 // In case of success, assign the result to VAR.
 //
 // Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
-#define BINJS_TRY_VAR(VAR, EXPR)                  \
-  do {                                            \
-    VAR = EXPR;                                   \
-    if (!VAR) return cx_->alreadyReportedError(); \
+#define BINJS_TRY_VAR(VAR, EXPR)          \
+  do {                                    \
+    (VAR) = (EXPR);                       \
+    if (MOZ_UNLIKELY(!(VAR))) {           \
+      return cx_->alreadyReportedError(); \
+    }                                     \
   } while (false)
 
 // Evaluate an expression EXPR, checking that the result is not falsy.
 // In case of success, assign the result to a new variable VAR.
 //
 // Throw `cx->alreadyReportedError()` if it returns 0/nullptr.
-#define BINJS_TRY_DECL(VAR, EXPR) \
-  auto VAR = EXPR;                \
-  if (!VAR) return cx_->alreadyReportedError();
+#define BINJS_TRY_DECL(VAR, EXPR)       \
+  auto (VAR) = (EXPR);                  \
+  if (MOZ_UNLIKELY(!(VAR))) {           \
+    return cx_->alreadyReportedError(); \
+  }
 
-#define BINJS_TRY_EMPL(VAR, EXPR)                            \
-  do {                                                       \
-    auto _tryEmplResult = EXPR;                              \
-    if (!_tryEmplResult) return cx_->alreadyReportedError(); \
-    VAR.emplace(_tryEmplResult.unwrap());                    \
+#define BINJS_TRY_EMPL(VAR, EXPR)           \
+  do {                                      \
+    auto _tryEmplResult = (EXPR);           \
+    if (MOZ_UNLIKELY(!_tryEmplResult)) {    \
+      return cx_->alreadyReportedError();   \
+    }                                       \
+    (VAR).emplace(_tryEmplResult.unwrap()); \
   } while (false)
 
 #define BINJS_MOZ_TRY_EMPLACE(VAR, EXPR)                 \
   do {                                                   \
-    auto _tryEmplResult = EXPR;                          \
-    if (_tryEmplResult.isErr())                          \
+    auto _tryEmplResult = (EXPR);                        \
+    if (MOZ_UNLIKELY(_tryEmplResult.isErr())) {          \
       return ::mozilla::Err(_tryEmplResult.unwrapErr()); \
-    VAR.emplace(_tryEmplResult.unwrap());                \
+    }                                                    \
+    (VAR).emplace(_tryEmplResult.unwrap());              \
   } while (false)
 
 // Evaluate an expression EXPR, checking that the result is a success.
 // In case of success, unwrap and assign the result to a new variable VAR.
 //
 // In case of error, propagate the error.
-#define BINJS_MOZ_TRY_DECL(VAR, EXPR)                            \
-  auto _##VAR = EXPR;                                            \
-  if (_##VAR.isErr()) return ::mozilla::Err(_##VAR.unwrapErr()); \
-  auto VAR = _##VAR.unwrap();
+#define BINJS_MOZ_TRY_DECL(VAR, EXPR)          \
+  auto _##VAR = (EXPR);                        \
+  if (MOZ_UNLIKELY(_##VAR.isErr())) {          \
+    return ::mozilla::Err(_##VAR.unwrapErr()); \
+  }                                            \
+  auto (VAR) = _##VAR.unwrap();
 
 #endif  // frontend_BinAST_macros_h