]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
long_format(): Simplify new code a bit.
authorTim Peters <tim.peters@gmail.com>
Sat, 14 Jul 2001 11:01:28 +0000 (11:01 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 14 Jul 2001 11:01:28 +0000 (11:01 +0000)
Objects/longobject.c

index 53ae5ed6bd237ffa39e995c96d083c22f37d7c36..b9cc9242ec2c5de1baa65c3b4ee5baf8d15a93cf 100644 (file)
@@ -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);
        }