8000 Branchless add · python/cpython@fbb1b12 · GitHub
[go: up one dir, main page]

Skip to content

Commit fbb1b12

Browse files
Branchless add
1 parent ce1319a commit fbb1b12

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Include/object.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ typedef struct _typeobject PyTypeObject;
9393
/* The GC bit-shifts refcounts left by two, and after that shift we still
9494
* need this to be >> 0, so leave three high zero bits (the sign bit and
9595
* room for a shift of two.) */
96-
#define _Py_IMMORTAL_BIT (1LL << (8 * sizeof(Py_ssize_t) - 4))
96+
#define _Py_IMMORTAL_BIT_OFFSET (8 * sizeof(Py_ssize_t) - 4)
97+
#define _Py_IMMORTAL_BIT (1LL << _Py_IMMORTAL_BIT_OFFSET)
9798

9899
#endif /* Py_IMMORTAL_OBJECTS */
99100

@@ -551,11 +552,10 @@ static inline void _Py_INCREF(PyObject *op)
551552
_Py_RefTotal++;
552553
#endif
553554
#ifdef Py_IMMORTAL_OBJECTS
554-
if (_Py_IsImmortal(op)) {
555-
return;
556-
}
557-
#endif /* Py_IMMORTAL_OBJECTS */
555+
op->ob_refcnt += !(op->ob_refcnt >> _Py_IMMORTAL_BIT_OFFSET);
556+
#else
558557
op->ob_refcnt++;
558+
#endif /* Py_IMMORTAL_OBJECTS */
559559
#endif
560560
}
561561
#define Py_INCREF(op) _Py_INCREF(_PyObject_CAST(op))

0 commit comments

Comments
 (0)
0