@@ -232,13 +232,6 @@ PyObject *CPyBool_Str(bool b) {
232232 return PyObject_Str (b ? Py_True : Py_False );
233233}
234234
235- static void CPyLong_NormalizeUnsigned (PyLongObject * v ) {
236- Py_ssize_t i = CPY_LONG_SIZE_UNSIGNED (v );
237- while (i > 0 && CPY_LONG_DIGIT (v , i - 1 ) == 0 )
238- i -- ;
239- CPyLong_SetUnsignedSize (v , i );
240- }
241-
242235// Bitwise op '&', '|' or '^' using the generic (slow) API
243236static CPyTagged GenericBitwiseOp (CPyTagged a , CPyTagged b , char op ) {
244237 PyObject * aobj = CPyTagged_AsObject (a );
@@ -302,7 +295,6 @@ CPyTagged CPyTagged_BitwiseLongOp_(CPyTagged a, CPyTagged b, char op) {
302295 digit * adigits = GetIntDigits (a , & asize , abuf );
303296 digit * bdigits = GetIntDigits (b , & bsize , bbuf );
304297
305- PyLongObject * r ;
306298 if (unlikely (asize < 0 || bsize < 0 )) {
307299 // Negative operand. This is slower, but bitwise ops on them are pretty rare.
308300 return GenericBitwiseOp (a , b , op );
@@ -317,31 +309,31 @@ CPyTagged CPyTagged_BitwiseLongOp_(CPyTagged a, CPyTagged b, char op) {
317309 asize = bsize ;
318310 bsize = tmp_size ;
319311 }
320- r = _PyLong_New (op == '&' ? asize : bsize );
321- if (unlikely (r == NULL )) {
312+ void * digits = NULL ;
313+ PyLongWriter * writer = PyLongWriter_Create (0 , op == '&' ? asize : bsize , & digits );
314+ if (unlikely (writer == NULL )) {
322315 CPyError_OutOfMemory ();
323316 }
324317 Py_ssize_t i ;
325318 if (op == '&' ) {
326319 for (i = 0 ; i < asize ; i ++ ) {
327- CPY_LONG_DIGIT ( r , i ) = adigits [i ] & bdigits [i ];
320+ (( digit * ) digits )[ i ] = adigits [i ] & bdigits [i ];
328321 }
329322 } else {
330323 if (op == '|' ) {
331324 for (i = 0 ; i < asize ; i ++ ) {
332- CPY_LONG_DIGIT ( r , i ) = adigits [i ] | bdigits [i ];
325+ (( digit * ) digits )[ i ] = adigits [i ] | bdigits [i ];
333326 }
334327 } else {
335328 for (i = 0 ; i < asize ; i ++ ) {
336- CPY_LONG_DIGIT ( r , i ) = adigits [i ] ^ bdigits [i ];
329+ (( digit * ) digits )[ i ] = adigits [i ] ^ bdigits [i ];
337330 }
338331 }
339332 for (; i < bsize ; i ++ ) {
340- CPY_LONG_DIGIT ( r , i ) = bdigits [i ];
333+ (( digit * ) digits )[ i ] = bdigits [i ];
341334 }
342335 }
343- CPyLong_NormalizeUnsigned (r );
344- return CPyTagged_StealFromObject ((PyObject * )r );
336+ return CPyTagged_StealFromObject (PyLongWriter_Finish (writer ));
345337}
346338
347339// Bitwise '~' slow path
0 commit comments