Skip to content

Commit

Permalink
Deleting some unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-griffiths committed Jun 12, 2024
1 parent 90544e8 commit bcf7176
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 77 deletions.
72 changes: 1 addition & 71 deletions bitformat/bits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import struct
import io
import re
from collections import abc
from typing import Union, Iterable, Any, TextIO, overload, Iterator, Type, TypeVar
import bitformat
Expand Down Expand Up @@ -111,10 +110,8 @@ def _create_from_bitstype(cls: Type[TBits], auto: BitsType, /) -> TBits:
b = super().__new__(cls)
if isinstance(auto, str):
b._bitstore = bitstore_helpers.str_to_bitstore(auto)
elif isinstance(auto, Bits):
b._bitstore = auto._bitstore.copy()
elif isinstance(auto, (bytes, bytearray, memoryview)):
b._bitstore = BitStore.frombytes(bytearray(auto))
b._bitstore = BitStore.frombytes(bytes(auto))
elif isinstance(auto, io.BytesIO):
b._bitstore = BitStore.frombytes(auto.getvalue())
elif isinstance(auto, abc.Iterable):
Expand Down Expand Up @@ -562,59 +559,6 @@ def _addright(self, bs: Bits, /) -> None:
"""Add a bitstring to the RHS of the current bitstring."""
self._bitstore += bs._bitstore

def _addleft(self, bs: Bits, /) -> None:
"""Prepend a bitstring to the current bitstring."""
if bs._bitstore.immutable:
self._bitstore = bs._bitstore._copy() + self._bitstore
else:
self._bitstore = bs._bitstore + self._bitstore

def _truncateleft(self: TBits, bits: int, /) -> TBits:
"""Truncate bits from the start of the bitstring. Return the truncated bits."""
assert 0 <= bits <= len(self)
if bits == 0:
return self.__class__()
truncated_bits = self._absolute_slice(0, bits)
if bits == len(self):
self._clear()
return truncated_bits
self._bitstore = self._bitstore.getslice_msb0(bits, None)
return truncated_bits

def _truncateright(self: TBits, bits: int, /) -> TBits:
"""Truncate bits from the end of the bitstring. Return the truncated bits."""
assert 0 <= bits <= len(self)
if bits == 0:
return self.__class__()
truncated_bits = self._absolute_slice(len(self) - bits, len(self))
if bits == len(self):
self._clear()
return truncated_bits
self._bitstore = self._bitstore.getslice_msb0(None, -bits)
return truncated_bits

def _insert(self, bs: Bits, pos: int, /) -> None:
"""Insert bs at pos."""
assert 0 <= pos <= len(self)
self._bitstore[pos: pos] = bs._bitstore
return

def _overwrite(self, bs: Bits, pos: int, /) -> None:
"""Overwrite with bs at pos."""
assert 0 <= pos <= len(self)
if bs is self:
# Just overwriting with self, so do nothing.
assert pos == 0
return
self._bitstore[pos: pos + len(bs)] = bs._bitstore

def _delete(self, bits: int, pos: int, /) -> None:
"""Delete bits at pos."""
assert 0 <= pos <= len(self)
assert pos + bits <= len(self), f"pos={pos}, bits={bits}, len={len(self)}"
del self._bitstore[pos: pos + bits]
return

def _reversebytes(self, start: int, end: int) -> None:
"""Reverse bytes in-place."""
assert (end - start) % 8 == 0
Expand All @@ -630,20 +574,6 @@ def _invert_all(self) -> None:
"""Invert every bit."""
self._bitstore.invert()

def _ilshift(self: TBits, n: int, /) -> TBits:
"""Shift bits by n to the left in place. Return self."""
assert 0 < n <= len(self)
self._addright(Bits(n))
self._truncateleft(n)
return self

def _irshift(self: TBits, n: int, /) -> TBits:
"""Shift bits by n to the right in place. Return self."""
assert 0 < n <= len(self)
self._addleft(Bits(n))
self._truncateright(n)
return self

def _imul(self: TBits, n: int, /) -> TBits:
"""Concatenate n copies of self in place. Return self."""
assert n >= 0
Expand Down
6 changes: 0 additions & 6 deletions bitformat/bitstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,6 @@ def _copy(self) -> BitStore:
s_copy._bitarray = copy.copy(self._bitarray)
return s_copy

def copy(self) -> BitStore:
return self

def __getitem__(self, item: Union[int, slice], /) -> Union[int, BitStore]:
# Use getindex or getslice instead
raise NotImplementedError
Expand Down Expand Up @@ -201,6 +198,3 @@ def setitem(self, key, value, /):
self._bitarray.__setitem__(key, value._bitarray)
else:
self._bitarray.__setitem__(key, value)

def delitem(self, key, /):
self._bitarray.__delitem__(key)

0 comments on commit bcf7176

Please sign in to comment.