Commit 3b3e5863 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Optimize PyObject_Malloc slightly

parent 4f9fa37b
...@@ -783,15 +783,6 @@ PyObject_Malloc(size_t nbytes) ...@@ -783,15 +783,6 @@ PyObject_Malloc(size_t nbytes)
goto redirect; goto redirect;
#endif #endif
/*
* Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes.
* Most python internals blindly use a signed Py_ssize_t to track
* things without checking for overflows or negatives.
* As size_t is unsigned, checking for nbytes < 0 is not required.
*/
if (UNLIKELY(nbytes > PY_SSIZE_T_MAX))
return NULL;
/* /*
* This implicitly redirects malloc(0). * This implicitly redirects malloc(0).
*/ */
...@@ -955,6 +946,18 @@ PyObject_Malloc(size_t nbytes) ...@@ -955,6 +946,18 @@ PyObject_Malloc(size_t nbytes)
goto init_pool; goto init_pool;
} }
// Pyston change: move this unlikely case below the likely one.
// This is ok because the two cases don't overlap.
/*
* Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes.
* Most python internals blindly use a signed Py_ssize_t to track
* things without checking for overflows or negatives.
* As size_t is unsigned, checking for nbytes < 0 is not required.
*/
if (UNLIKELY(nbytes > PY_SSIZE_T_MAX))
return NULL;
/* The small block allocator ends here. */ /* The small block allocator ends here. */
redirect: redirect:
......
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