py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions.

There are two checks that are always false so can be converted to (negated)
assertions to save code space and execution time.  They are:

1. The check of the str parameter, which is required to be non-NULL as per
   the original comment that it has enough space in it as calculated by
   mp_int_format_size.  And for all uses of this function str is indeed
   non-NULL.

2. The check of the base parameter, which is already required to be between
   2 and 16 (inclusive) via the assertion in mp_int_format_size.
This commit is contained in:
Damien George 2017-12-28 14:14:06 +11:00
parent 9766fddcdc
commit e784274430
1 changed files with 4 additions and 8 deletions

View File

@ -1647,16 +1647,12 @@ char *mpz_as_str(const mpz_t *i, unsigned int base) {
}
#endif
// assumes enough space as calculated by mp_int_format_size
// assumes enough space in str as calculated by mp_int_format_size
// base must be between 2 and 32 inclusive
// returns length of string, not including null byte
size_t mpz_as_str_inpl(const mpz_t *i, unsigned int base, const char *prefix, char base_char, char comma, char *str) {
if (str == NULL) {
return 0;
}
if (base < 2 || base > 32) {
str[0] = 0;
return 0;
}
assert(str != NULL);
assert(2 <= base && base <= 32);
size_t ilen = i->len;