diff --git a/swarm/manager.py b/swarm/manager.py index fd3adad..9828048 100644 --- a/swarm/manager.py +++ b/swarm/manager.py @@ -243,10 +243,10 @@ class Manager: self.bits_toggled_off = len(bits_off) for ndx in bits_on: - byte, bit = divmod(ndx, 8) + byte, bit = ndx >> 3, ndx & 7 self.shmem.buf[OFFSET_STATE + byte] |= 0x80 >> bit for ndx in bits_off: - byte, bit = divmod(ndx, 8) + byte, bit = ndx >> 3, ndx & 7 self.shmem.buf[OFFSET_STATE + byte] &= 0xFF ^ (0x80 >> bit) since_last_printout = time.time() - self.last_printout @@ -268,7 +268,7 @@ class Manager: with Image.new("RGB", (1000, 1000), 0) as im: for i in range(1000000): y, x = divmod(i, 1000) - byte, bit = divmod(i, 8) + byte, bit = i >> 3, i & 7 im.putpixel( (x, y), ( @@ -285,7 +285,7 @@ class Manager: with Image.new("L", (1000, 1000), 0) as im: for i in range(1000000): y, x = divmod(i, 1000) - byte, bit = divmod(i, 8) + byte, bit = i >> 3, i & 7 im.putpixel( (x, y), 255 if (buf[OFFSET_AVOID + byte] << bit) & 0x80 else 0, @@ -313,7 +313,7 @@ class Manager: def add_avoid_range(self, rng: range): assert self.shmem is not None for ndx in rng: - byte, bit = divmod(ndx, 8) + byte, bit = ndx >> 3, ndx & 7 self.shmem.buf[OFFSET_AVOID + byte] |= 0x80 >> bit def add_avoid_rect(self, sx: int, sy: int, w: int, h: int): @@ -324,7 +324,7 @@ class Manager: def add_avoid_index(self, index: int): assert self.shmem is not None assert 0 <= index < 1000000 - byte, bit = divmod(index, 8) + byte, bit = index >> 3, index & 7 self.shmem.buf[OFFSET_AVOID + byte] |= 0x80 >> bit def add_avoid_image(self, im: Image.Image): @@ -342,7 +342,7 @@ class Manager: def set_index(self, index: int, value: bool): assert 0 <= index <= 1000000 assert self.shmem is not None - byte, bit = divmod(index, 8) + byte, bit = index >> 3, index & 7 self.shmem.buf[OFFSET_MASK + byte] |= 0x80 >> bit if value: self.shmem.buf[OFFSET_CANVAS + byte] |= 0x80 >> bit @@ -352,7 +352,7 @@ class Manager: def clear_index(self, index: int): assert 0 <= index <= 1000000 assert self.shmem is not None - byte, bit = divmod(index, 8) + byte, bit = index >> 3, index & 7 self.shmem.buf[OFFSET_MASK + byte] &= 0xFF ^ (0x80 >> bit) self.shmem.buf[OFFSET_CANVAS + byte] &= 0xFF ^ (0x80 >> bit)