[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r7022: And another GCC change: predict that tor_frees() are usually (in tor/trunk: . src/common)



Author: nickm
Date: 2006-08-11 03:09:35 -0400 (Fri, 11 Aug 2006)
New Revision: 7022

Modified:
   tor/trunk/
   tor/trunk/src/common/compat.h
   tor/trunk/src/common/util.h
Log:
 r7326@Kushana:  nickm | 2006-08-10 23:50:49 -0700
 And another GCC change: predict that tor_frees() are usually real frees, and tor_asserts() usually wont happen. Other test should wait till -fprofile-arcs



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - 17f730b7-d419-0410-b50f-85ee4b70197a:/local/or/tor/trunk:8245
1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
96637b51-b116-0410-a10e-9941ebb49b64:/tor/branches/spec:7005
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7014
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7030
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/trans-ap:7315
c95137ef-5f19-0410-b913-86e773d04f59:/tor/trunk:7325
   + 17f730b7-d419-0410-b50f-85ee4b70197a:/local/or/tor/trunk:8245
1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
96637b51-b116-0410-a10e-9941ebb49b64:/tor/branches/spec:7005
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7014
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/mmap:7030
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/trans-ap:7315
c95137ef-5f19-0410-b913-86e773d04f59:/tor/trunk:7326

Modified: tor/trunk/src/common/compat.h
===================================================================
--- tor/trunk/src/common/compat.h	2006-08-11 07:09:28 UTC (rev 7021)
+++ tor/trunk/src/common/compat.h	2006-08-11 07:09:35 UTC (rev 7022)
@@ -95,11 +95,13 @@
 #define ATTR_PURE __attribute__((pure))
 #define ATTR_MALLOC __attribute__((malloc))
 #define ATTR_NONNULL(x) __attribute__((nonnull x))
+#define PREDICT(exp, val) __builtin_expect((exp), (val))
 #else
 #define ATTR_NORETURN
 #define ATTR_PURE
 #define ATTR_MALLOC
 #define ATTR_NONNULL(x)
+#define PREDICT(exp, val)
 #endif
 
 /* ===== String compatibility */

Modified: tor/trunk/src/common/util.h
===================================================================
--- tor/trunk/src/common/util.h	2006-08-11 07:09:28 UTC (rev 7021)
+++ tor/trunk/src/common/util.h	2006-08-11 07:09:35 UTC (rev 7022)
@@ -38,12 +38,17 @@
  */
 #error "Sorry; we don't support building with NDEBUG."
 #else
+#ifdef __GNUC__
+#define PREDICT_FALSE(x) PREDICT((x) != ((typeof(x)) 0), 0)
+#else
+#define PREDICT_FALSE(x) !(x)
+#endif
 #define tor_assert(expr) do {                                           \
-    if (!(expr)) {                                                      \
+    if (PREDICT_FALSE(expr)) {                                          \
       log(LOG_ERR, LD_BUG, "%s:%d: %s: Assertion %s failed; aborting.", \
-          _SHORT_FILE_, __LINE__, __func__, #expr);                 \
+          _SHORT_FILE_, __LINE__, __func__, #expr);                     \
       fprintf(stderr,"%s:%d %s: Assertion %s failed; aborting.\n",      \
-              _SHORT_FILE_, __LINE__, __func__, #expr);             \
+              _SHORT_FILE_, __LINE__, __func__, #expr);                 \
       abort();                                                          \
     } } while (0)
 #endif
@@ -74,13 +79,14 @@
 extern int dmalloc_free(const char *file, const int line, void *pnt,
                         const int func_id);
 #define tor_free(p) do { \
-    if (p) {                                        \
+    if (PREDICT((p)!=NULL, 1) {                     \
       dmalloc_free(_SHORT_FILE_, __LINE__, (p), 0); \
       (p)=NULL;                                     \
     }                                               \
   } while (0)
 #else
-#define tor_free(p) do { if (p) {free(p); (p)=NULL;} } while (0)
+#define tor_free(p) do { if (PREDICT((p)!=NULL,1)) { free(p); (p)=NULL;} } \
+  while (0)
 #endif
 
 #define tor_malloc(size)       _tor_malloc(size DMALLOC_ARGS)