STINNER Victor added the comment:
> Here's example:
> https://github.com/sir-sigurd/cpython/commit/c8699d0c614a18d558216ae7d432107147c95c28.
"_Py_ASSUME((size_t)size <= MAX_LONG_DIGITS);"
Typically, such code use assert() and is removed for release build.
assert() is more for contract base
Sergey Fedoseev added the comment:
> If you care of _PyLong_Copy() performance, you should somehow manually inline
> _PyLong_New() inside _PyLong_Copy().
It doesn't solve this:
> We could add a function that bypass that check, but in LTO build
> PyObject_MALLOC() is inlined into _PyLong_New
STINNER Victor added the comment:
> This check is redundant when _PyLong_New() is called from _PyLong_Copy().
If you care of _PyLong_Copy() performance, you should somehow manually inline
_PyLong_New() inside _PyLong_Copy().
--
___
Python tracker
STINNER Victor added the comment:
> Real world example. _PyLong_Copy() [1] calls _PyLong_New() [2]. _PyLong_New()
> checks the size, so that overflow does not occur. This check is redundant
> when _PyLong_New() is called from _PyLong_Copy(). We could add a function
> that bypass that check,
New submission from Sergey Fedoseev :
GCC (along with Clang and ICC) has __builtin_unreachable() and MSVC has
__assume() builtins, that can be used to optimize out unreachable conditions.
So we could add macro like this:
#ifdef Py_DEBUG
# define Py_ASSUME(cond) (assert(cond))
#else
# if d