@@ -232,13 +232,6 @@ PyObject *CPyBool_Str(bool b) {
232
232
return PyObject_Str (b ? Py_True : Py_False );
233
233
}
234
234
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
-
242
235
// Bitwise op '&', '|' or '^' using the generic (slow) API
243
236
static CPyTagged GenericBitwiseOp (CPyTagged a , CPyTagged b , char op ) {
244
237
PyObject * aobj = CPyTagged_AsObject (a );
@@ -302,7 +295,6 @@ CPyTagged CPyTagged_BitwiseLongOp_(CPyTagged a, CPyTagged b, char op) {
302
295
digit * adigits = GetIntDigits (a , & asize , abuf );
303
296
digit * bdigits = GetIntDigits (b , & bsize , bbuf );
304
297
305
- PyLongObject * r ;
306
298
if (unlikely (asize < 0 || bsize < 0 )) {
307
299
// Negative operand. This is slower, but bitwise ops on them are pretty rare.
308
300
return GenericBitwiseOp (a , b , op );
@@ -317,31 +309,31 @@ CPyTagged CPyTagged_BitwiseLongOp_(CPyTagged a, CPyTagged b, char op) {
317
309
asize = bsize ;
318
310
bsize = tmp_size ;
319
311
}
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 )) {
322
315
CPyError_OutOfMemory ();
323
316
}
324
317
Py_ssize_t i ;
325
318
if (op == '&' ) {
326
319
for (i = 0 ; i < asize ; i ++ ) {
327
- CPY_LONG_DIGIT ( r , i ) = adigits [i ] & bdigits [i ];
320
+ (( digit * ) digits )[ i ] = adigits [i ] & bdigits [i ];
328
321
}
329
322
} else {
330
323
if (op == '|' ) {
331
324
for (i = 0 ; i < asize ; i ++ ) {
332
- CPY_LONG_DIGIT ( r , i ) = adigits [i ] | bdigits [i ];
325
+ (( digit * ) digits )[ i ] = adigits [i ] | bdigits [i ];
333
326
}
334
327
} else {
335
328
for (i = 0 ; i < asize ; i ++ ) {
336
- CPY_LONG_DIGIT ( r , i ) = adigits [i ] ^ bdigits [i ];
329
+ (( digit * ) digits )[ i ] = adigits [i ] ^ bdigits [i ];
337
330
}
338
331
}
339
332
for (; i < bsize ; i ++ ) {
340
- CPY_LONG_DIGIT ( r , i ) = bdigits [i ];
333
+ (( digit * ) digits )[ i ] = bdigits [i ];
341
334
}
342
335
}
343
- CPyLong_NormalizeUnsigned (r );
344
- return CPyTagged_StealFromObject ((PyObject * )r );
336
+ return CPyTagged_StealFromObject (PyLongWriter_Finish (writer ));
345
337
}
346
338
347
339
// Bitwise '~' slow path
0 commit comments