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

Add some LIKELY annotations to obmalloc

parent 147549c9
......@@ -9,9 +9,13 @@
#endif
#endif
#define UNLIKELY(value) __builtin_expect((value), 0)
#define LIKELY(value) __builtin_expect((value), 1)
#ifdef WITH_VALGRIND
#include <valgrind/valgrind.h>
#if 0
/* If we're using GCC, use __builtin_expect() to reduce overhead of
the valgrind checks */
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
......@@ -19,6 +23,7 @@
#else
# define UNLIKELY(value) (value)
#endif
#endif
/* -1 indicates that we haven't checked that we're running on valgrind yet. */
static int running_on_valgrind = -1;
......@@ -784,20 +789,20 @@ PyObject_Malloc(size_t nbytes)
* things without checking for overflows or negatives.
* 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;
/*
* This implicitly redirects malloc(0).
*/
if ((nbytes - 1) < SMALL_REQUEST_THRESHOLD) {
if (LIKELY((nbytes - 1) < SMALL_REQUEST_THRESHOLD)) {
LOCK();
/*
* Most frequent paths first
*/
size = (uint)(nbytes - 1) >> ALIGNMENT_SHIFT;
pool = usedpools[size + size];
if (pool != pool->nextpool) {
if (LIKELY(pool != pool->nextpool)) {
/*
* There is a used pool for this size class.
* 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