Commit 6466fee0 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Add some LIKELY annotations to obmalloc

parent 147549c9
...@@ -9,9 +9,13 @@ ...@@ -9,9 +9,13 @@
#endif #endif
#endif #endif
#define UNLIKELY(value) __builtin_expect((value), 0)
#define LIKELY(value) __builtin_expect((value), 1)
#ifdef WITH_VALGRIND #ifdef WITH_VALGRIND
#include <valgrind/valgrind.h> #include <valgrind/valgrind.h>
#if 0
/* If we're using GCC, use __builtin_expect() to reduce overhead of /* If we're using GCC, use __builtin_expect() to reduce overhead of
the valgrind checks */ the valgrind checks */
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
...@@ -19,6 +23,7 @@ ...@@ -19,6 +23,7 @@
#else #else
# define UNLIKELY(value) (value) # define UNLIKELY(value) (value)
#endif #endif
#endif
/* -1 indicates that we haven't checked that we're running on valgrind yet. */ /* -1 indicates that we haven't checked that we're running on valgrind yet. */
static int running_on_valgrind = -1; static int running_on_valgrind = -1;
...@@ -784,20 +789,20 @@ PyObject_Malloc(size_t nbytes) ...@@ -784,20 +789,20 @@ PyObject_Malloc(size_t nbytes)
* things without checking for overflows or negatives. * things without checking for overflows or negatives.
* As size_t is unsigned, checking for nbytes < 0 is not required. * As size_t is unsigned, checking for nbytes < 0 is not required.
*/ */
if (nbytes > PY_SSIZE_T_MAX) if (UNLIKELY(nbytes > PY_SSIZE_T_MAX))
return NULL; return NULL;
/* /*
* This implicitly redirects malloc(0). * This implicitly redirects malloc(0).
*/ */
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) { if (LIKELY((nbytes - 1) < SMALL_REQUEST_THRESHOLD)) {
LOCK(); LOCK();
/* /*
* Most frequent paths first * Most frequent paths first
*/ */
size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT; size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT;
pool = usedpools[size + size]; pool = usedpools[size + size];
if (pool != pool->nextpool) { if (LIKELY(pool != pool->nextpool)) {
/* /*
* There is a used pool for this size class. * There is a used pool for this size class.
* Pick up the head block of its free list. * Pick up the head block of its free list.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment