Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8a6b9b

Browse files
committed
long_format(): Simplify new code a bit.
1 parent 8600b47 commit c8a6b9b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Objects/longobject.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,17 +840,20 @@ long_format(PyObject *aa, int base, int addL)
840840
Py_DECREF(str);
841841
return NULL;
842842
})
843-
while (--ntostore >= 0) {
843+
assert(ntostore > 0);
844+
do {
844845
digit nextrem = (digit)(rem / base);
845846
char c = (char)(rem - nextrem * base);
846847
assert(p > PyString_AS_STRING(str));
847848
c += (c < 10) ? '0' : 'A'-10;
848849
*--p = c;
849850
rem = nextrem;
850-
if (a->ob_size == 0 && rem == 0)
851-
break; /* skip leading zeroes */
852-
}
853-
} while (ABS(a->ob_size) != 0);
851+
--ntostore;
852+
/* Termination is a bit delicate: must not
853+
store leading zeroes, so must get out if
854+
a and rem are both 0 now. */
855+
} while (ntostore && (a->ob_size || rem));
856+
} while (a->ob_size != 0);
854857
Py_DECREF(a);
855858
}
856859

0 commit comments

Comments
 (0)