summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-07-14 11:01:28 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-07-14 11:01:28 (GMT)
commitc8a6b9b6d67c4bf343f3771fcae0002160066fe3 (patch)
tree2bcbad7acc2f6f643d2476a66fd3c027a90d7907
parent8600b47b61ab9d3fd5cae0bf2f1559c98e42f5da (diff)
downloadcpython-c8a6b9b6d67c4bf343f3771fcae0002160066fe3.zip
cpython-c8a6b9b6d67c4bf343f3771fcae0002160066fe3.tar.gz
cpython-c8a6b9b6d67c4bf343f3771fcae0002160066fe3.tar.bz2
long_format(): Simplify new code a bit.
-rw-r--r--Objects/longobject.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 53ae5ed..b9cc924 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -840,17 +840,20 @@ long_format(PyObject *aa, int base, int addL)
Py_DECREF(str);
return NULL;
})
- while (--ntostore >= 0) {
+ assert(ntostore > 0);
+ do {
digit nextrem = (digit)(rem / base);
char c = (char)(rem - nextrem * base);
assert(p > PyString_AS_STRING(str));
c += (c < 10) ? '0' : 'A'-10;
*--p = c;
rem = nextrem;
- if (a->ob_size == 0 && rem == 0)
- break; /* skip leading zeroes */
- }
- } while (ABS(a->ob_size) != 0);
+ --ntostore;
+ /* Termination is a bit delicate: must not
+ store leading zeroes, so must get out if
+ a and rem are both 0 now. */
+ } while (ntostore && (a->ob_size || rem));
+ } while (a->ob_size != 0);
Py_DECREF(a);
}