Skip to content

Commit

Permalink
add IS_LE and IS_BE macros to header
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanschnell committed Mar 20, 2022
1 parent cfd2769 commit 14655cf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions bitarray/_bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ shift_r8(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b, int n, int bebr)

/* as the big-endian representation has reversed bit order in each
byte, we reverse each byte, and (re-) reverse again below */
if (bebr && self->endian == ENDIAN_BIG)
if (bebr && IS_BE(self))
bytereverse(self, a, b);
#define ucb ((unsigned char *) (self)->ob_item)

Expand Down Expand Up @@ -262,7 +262,7 @@ shift_r8(bitarrayobject *self, Py_ssize_t a, Py_ssize_t b, int n, int bebr)
}
}
#undef ucb
if (bebr && self->endian == ENDIAN_BIG) /* (re-) reverse bytes */
if (bebr && IS_BE(self)) /* (re-) reverse bytes */
bytereverse(self, a, b);
}

Expand Down Expand Up @@ -311,8 +311,8 @@ copy_n(bitarrayobject *self, Py_ssize_t a,
int sa = a % 8;
int sb = -(b % 8);
char t1, t2, t3;
char m1 = ones_table[self->endian == ENDIAN_BIG][sa];
char m2 = ones_table[self->endian == ENDIAN_BIG][(a + n) % 8];
char m1 = ones_table[IS_BE(self)][sa];
char m2 = ones_table[IS_BE(self)][(a + n) % 8];
Py_ssize_t i;

assert(n >= 8);
Expand Down Expand Up @@ -2070,7 +2070,7 @@ setslice_bool(bitarrayobject *self, PyObject *slice, PyObject *value)
setrange(self, start, stop, vi);
}
else {
const char *table = bitmask_table[self->endian == ENDIAN_BIG];
const char *table = bitmask_table[IS_BE(self)];
Py_ssize_t i;

assert(step > 1);
Expand Down
3 changes: 0 additions & 3 deletions bitarray/_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include "pythoncapi_compat.h"
#include "bitarray.h"

#define IS_LE(a) ((a)->endian == ENDIAN_LITTLE)
#define IS_BE(a) ((a)->endian == ENDIAN_BIG)

/* set using the Python module function _set_bato() */
static PyObject *bitarray_type_obj = NULL;

Expand Down
3 changes: 3 additions & 0 deletions bitarray/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ typedef struct {
#define ENDIAN_LITTLE 0
#define ENDIAN_BIG 1

#define IS_LE(self) ((self)->endian == ENDIAN_LITTLE)
#define IS_BE(self) ((self)->endian == ENDIAN_BIG)

/* the endianness string */
#define ENDIAN_STR(endian) ((endian) == ENDIAN_LITTLE ? "little" : "big")

Expand Down

0 comments on commit 14655cf

Please sign in to comment.