picop.cybytes#

Fast bytes accessors.

picop.cybytes.bytes_bytearray_eq(a, b)#

Return True if bytes/bytearray contents match.

Notes

Either argument order is accepted; compares with memcmp after a length gate.

Parameters:
Return type:

bool

picop.cybytes.bytes_check(p)#

Return True if p is bytes or a subtype (PyBytes_Check). :type p: object :param p:

Return type:

bool

Parameters:

p (object)

picop.cybytes.bytes_check_exact(p)#

Return True if type(p) is bytes (PyBytes_CheckExact). :type p: object :param p:

Return type:

bool

Parameters:

p (object)

picop.cybytes.bytes_contains(haystack, needle)#

Return True if needle is in haystack.

Notes

Uses memchr/memmem under 256B, else the builtin in path.

Parameters:
Return type:

bool

picop.cybytes.bytes_endswith(s, suffix)#

Return True if typed s ends with suffix.

Notes

Length gate plus tail memcmp on the typed suffix region.

Parameters:
Return type:

bool

picop.cybytes.bytes_eq(a, b)#

Return True if a == b.

Notes

Identity/len short-circuit plus memcmp on typed bytes.

Parameters:
Return type:

bool

picop.cybytes.bytes_from_object(o)#

Return bytes from a buffer-protocol object (PyBytes_FromObject). :type o: object :param o:

Return type:

bytes

picop.cybytes.bytes_len(b)#

Return len(b) via PyBytes_GET_SIZE. :type b: bytes :param b:

Return type:

int

Parameters:

b (bytes)

picop.cybytes.bytes_ne(a, b)#

Return True if a != b (inverse of bytes_eq). :type a: bytes :param a: :type b: bytes :param b:

Return type:

bool

Parameters:
picop.cybytes.bytes_size(b)#

Return len(b) via checked PyBytes_Size.

Notes

Prefer bytes_len on a typed bytes hot path.

Parameters:

b (object)

Return type:

int

picop.cybytes.bytes_startswith(s, prefix)#

Return True if typed s begins with prefix.

Notes

Length gate plus memcmp on the typed prefix region.

Parameters:
Return type:

bool