From 820819a706e599b1555918eee44391c7e0e031e8 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Sat, 8 May 2021 15:09:00 -0500 Subject: [PATCH] simplify count_to_n() --- bitarray/_util.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/bitarray/_util.c b/bitarray/_util.c index 35d8362a..435aea17 100644 --- a/bitarray/_util.c +++ b/bitarray/_util.c @@ -46,7 +46,6 @@ count_to_n(bitarrayobject *a, Py_ssize_t n) Py_ssize_t i = 0; /* index */ Py_ssize_t j = 0; /* total count up to index */ Py_ssize_t block_start, block_stop, k, m; - unsigned char c; if (n == 0) return 0; @@ -58,11 +57,9 @@ count_to_n(bitarrayobject *a, Py_ssize_t n) assert(i % 8 == 0); block_start = i / 8; block_stop = block_start + (BLOCK_BITS / 8); - for (k = block_start; k < block_stop; k++) { - assert(k < Py_SIZE(a)); - c = a->ob_item[k]; - m += bitcount_lookup[c]; - } + assert(block_stop <= Py_SIZE(a)); + for (k = block_start; k < block_stop; k++) + m += bitcount_lookup[(unsigned char) a->ob_item[k]]; if (j + m >= n) break; j += m; @@ -73,8 +70,7 @@ count_to_n(bitarrayobject *a, Py_ssize_t n) while (i + 8 < a->nbits) { k = i / 8; assert(k < Py_SIZE(a)); - c = a->ob_item[k]; - m = bitcount_lookup[c]; + m = bitcount_lookup[(unsigned char) a->ob_item[k]]; if (j + m >= n) break; j += m;