]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use __builtin_expect in Assert and AssertNothrow.
authorDavid Wells <wellsd2@rpi.edu>
Sun, 8 Apr 2018 17:40:03 +0000 (13:40 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sun, 8 Apr 2018 17:42:11 +0000 (13:42 -0400)
include/deal.II/base/exceptions.h

index e1371a9fbae8de09a291bb3793947902f7ee37e3..68661dad05ba68f13bfc5dd5d9b29ce5a2d48402 100644 (file)
@@ -347,15 +347,25 @@ namespace deal_II_exceptions
  * @author Wolfgang Bangerth, 1997, 1998, Matthias Maier, 2013
  */
 #ifdef DEBUG
-#define Assert(cond, exc)                                                   \
+#  ifdef DEAL_II_HAVE_BUILTIN_EXPECT
+#    define Assert(cond, exc)                                                 \
+  {                                                                           \
+    if (__builtin_expect(!(cond), false))                                     \
+      ::dealii::deal_II_exceptions::internals::                               \
+      issue_error(::dealii::deal_II_exceptions::internals::abort_on_exception,\
+                  __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
+  }
+#  else
+#    define Assert(cond, exc)                                                 \
   {                                                                           \
     if (!(cond))                                                              \
       ::dealii::deal_II_exceptions::internals::                               \
       issue_error(::dealii::deal_II_exceptions::internals::abort_on_exception,\
                   __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
   }
+#  endif
 #else
-#define Assert(cond, exc)                                                   \
+#define Assert(cond, exc)                                                     \
   {}
 #endif
 
@@ -377,7 +387,17 @@ namespace deal_II_exceptions
  * @author Wolfgang Bangerth, 1997, 1998, Matthias Maier, 2013
  */
 #ifdef DEBUG
-#define AssertNothrow(cond, exc)                                              \
+#  ifdef DEAL_II_HAVE_BUILTIN_EXPECT
+#    define AssertNothrow(cond, exc)                                            \
+  {                                                                             \
+    if (__builtin_expect(!(cond), false))                                       \
+      ::dealii::deal_II_exceptions::internals::                                 \
+      issue_error_nothrow(                                                      \
+          ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception,  \
+          __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc);           \
+  }
+#  else
+#    define AssertNothrow(cond, exc)                                            \
   {                                                                             \
     if (!(cond))                                                                \
       ::dealii::deal_II_exceptions::internals::                                 \
@@ -385,6 +405,7 @@ namespace deal_II_exceptions
           ::dealii::deal_II_exceptions::internals::abort_nothrow_on_exception,  \
           __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc);           \
   }
+#  endif
 #else
 #define AssertNothrow(cond, exc)                                              \
   {}
@@ -408,7 +429,7 @@ namespace deal_II_exceptions
  * @author Wolfgang Bangerth, 1997, 1998, Matthias Maier, 2013
  */
 #ifdef DEAL_II_HAVE_BUILTIN_EXPECT
-#define AssertThrow(cond, exc)                                              \
+#define AssertThrow(cond, exc)                                                \
   {                                                                           \
     if (__builtin_expect(!(cond), false))                                     \
       ::dealii::deal_II_exceptions::internals::                               \
@@ -416,7 +437,7 @@ namespace deal_II_exceptions
                   __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, #exc, exc); \
   }
 #else /*ifdef DEAL_II_HAVE_BUILTIN_EXPECT*/
-#define AssertThrow(cond, exc)                                              \
+#define AssertThrow(cond, exc)                                                \
   {                                                                           \
     if (!(cond))                                                              \
       ::dealii::deal_II_exceptions::internals::                               \

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.