Skip to content

Commit 87c34b0

Browse files
committed
remove endianness argument from setup_table()
1 parent dd1f493 commit 87c34b0

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

bitarray/_bitarray.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4278,7 +4278,7 @@ PyInit__bitarray(void)
42784278

42794279
/* setup translation table, which maps each byte to its reversed:
42804280
reverse_trans = {0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, ..., 0xff} */
4281-
setup_table(reverse_trans, 0, 'r');
4281+
setup_table(reverse_trans, 'r');
42824282

42834283
if ((m = PyModule_Create(&moduledef)) == NULL)
42844284
return NULL;

bitarray/_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ sum_indices(PyObject *module, PyObject *obj)
295295
set_padbits(a);
296296

297297
if (setup != a->endian) {
298-
setup_table(table, IS_LE(a), 'a');
298+
setup_table(table, IS_LE(a) ? 'a' : 'A');
299299
setup = a->endian;
300300
}
301301

@@ -341,7 +341,7 @@ xor_indices(PyObject *module, PyObject *obj)
341341
set_padbits(a);
342342

343343
if (setup != a->endian) {
344-
setup_table(table, IS_LE(a), 'x');
344+
setup_table(table, IS_LE(a) ? 'x' : 'X');
345345
setup = a->endian;
346346
}
347347

bitarray/bitarray.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,21 @@ swap_bytes(char *p, Py_ssize_t n)
225225
}
226226
}
227227

228-
/* write 256 characters into table for given endianness, kernel operation */
228+
/* write 256 characters into table for given kernel operation */
229229
static inline void
230-
setup_table(char *table, int le, char kop)
230+
setup_table(char *table, char kop)
231231
{
232232
int j, k;
233233
for (k = 0; k < 256; k++) {
234234
table[k] = 0;
235235
for (j = 0; j < 8; j++) {
236-
if (( le && k & 0x01 << j) || /* little endian */
237-
(!le && k & 0x80 >> j)) /* big endian */
236+
if (k & 1 << j)
238237
switch (kop) {
239-
case 'a': table[k] += j; break;
240-
case 'x': table[k] ^= j; break;
241-
case 'r': table[k] |= 1 << j; break;
238+
case 'a': table[k] += j; break;
239+
case 'A': table[k] += 7 - j; break;
240+
case 'x': table[k] ^= j; break;
241+
case 'X': table[k] ^= 7 - j; break;
242+
case 'r': table[k] |= 128 >> j; break;
242243
default: Py_UNREACHABLE();
243244
}
244245
}

0 commit comments

Comments
 (0)