Skip to content

Commit db21da1

Browse files
committed
Add comment: only positive
1 parent 2d6ee26 commit db21da1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Objects/longobject.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ _PyLong_AssignValue(PyObject **target, Py_ssize_t value)
275275
Py_REFCNT(old) == 1 && Py_SIZE(old) == 1 &&
276276
(size_t)value <= PyLong_MASK)
277277
{
278-
// Mutate in place if there are no other references to the old object.
279-
// This avoids an allocation in a common case.
280-
((PyLongObject *)old)->ob_digit[0]
281-
= Py_SAFE_DOWNCAST(value, Py_ssize_t, digit);
278+
// Mutate in place if there are no other references the old
279+
// object. This avoids an allocation in a common case.
280+
// Since the primary use-case is iterating over ranges, which
281+
// are typically positive, only do this optimization
282+
// for positive integers (for now).
283+
((PyLongObject *)old)->ob_digit[0] =
284+
Py_SAFE_DOWNCAST(value, Py_ssize_t, digit);
282285
return 0;
283286
}
284287
else {

0 commit comments

Comments
 (0)