File tree 1 file changed +7
-4
lines changed
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -275,10 +275,13 @@ _PyLong_AssignValue(PyObject **target, Py_ssize_t value)
275
275
Py_REFCNT (old ) == 1 && Py_SIZE (old ) == 1 &&
276
276
(size_t )value <= PyLong_MASK )
277
277
{
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 );
282
285
return 0 ;
283
286
}
284
287
else {
You can’t perform that action at this time.
0 commit comments