picop.hot#
Curated micro-opt starters — prefer from picop.hot import … over the flat barrel.
Core frozen at 1.0 — this __all__ is part of the stable Core surface
(additive minors OK; removals need a major). Full public surface remains on
picop / picop.cy*. Soft letter/bare aliases were removed in 0.3.
See Quickstart and Safety.
- picop.hot.dict_get(d, key)#
Return
d[key]via borrowedPyDict_GetItem.Notes
Missing keys and stored
Noneboth yieldNone. Preferdict_get_refwhen you need to distinguish those cases.
- picop.hot.dict_set(d, key, value)#
Set
d[key] = valueviaPyDict_SetItem.Notes
Returns
0on success and-1on error; errors raise. Do not use the status int as a bool.
- picop.hot.dict_contains(d, key)#
Return whether
keyis ind(PyDict_Contains). :type d:dict:param d: :type key:str:param key:
- picop.hot.dict_pop(d, key)#
Remove
keyand return its value viaPyDict_Pop.Notes
Missing keys yield
None(same ambiguity as a storedNonevalue).
- picop.hot.dict_setdefault(d, key, default=None)#
Return
d.setdefault(key, default)via borrowedPyDict_SetDefault.Notes
The returned reference is borrowed. Prefer
dict_setdefault_refwhen you need a strong ref.
- picop.hot.list_get(l, i)#
Return
l[i]viaPyList_GET_ITEM.Notes
Unchecked: out-of-bounds is undefined behavior. Prefer
list_get_checked/list_get_refwhen the index may be OOB, or bound the index yourself before calling.
- picop.hot.list_get_checked(l, i)#
Return
l[i]via bounds-checkedPyList_GetItem.Notes
Raises
IndexErroron out-of-bounds (unlike uncheckedlist_get).
- picop.hot.list_append(l, value)#
Append
valueviaPyList_Append.Notes
Returns
0on success and-1on error; errors raise. Do not use the status int as a bool.
- picop.hot.set_contains(anyset, value)#
Return whether
valueis inanysetviaPySet_Contains. :type anyset:object:param anyset: :type value:object:param value:
- picop.hot.set_add(s, value)#
Add
valueviaPySet_Add.Notes
Returns
0on success; errors raise. Do not use the status int as a bool.
- picop.hot.tuple_get(t, i)#
Return
t[i]viaPyTuple_GET_ITEM.Notes
Unchecked: out-of-bounds is undefined behavior. Prefer
tuple_get_checkedwhen the index may be OOB, or bound the index yourself before calling.
- picop.hot.tuple_pack2(a, b)#
Return
(a, b)viaPyTuple_Pack. :type a:object:param a: :type b:object:param b:
- picop.hot.bytes_contains(haystack, needle)#
Return True if
needleis inhaystack.Notes
Uses
memchr/memmemunder 256B, else the builtininpath.
- picop.hot.bytes_eq(a, b)#
Return True if
a == b.Notes
Identity/len short-circuit plus
memcmpon typedbytes.
- picop.hot.bytes_ne(a, b)#
Return True if
a != b(inverse ofbytes_eq). :type a:bytes:param a: :type b:bytes:param b:
- picop.hot.bytes_startswith(s, prefix)#
Return True if typed
sbegins withprefix.Notes
Length gate plus
memcmpon the typed prefix region.
- picop.hot.bytes_endswith(s, suffix)#
Return True if typed
sends withsuffix.Notes
Length gate plus tail
memcmpon the typed suffix region.
- picop.hot.bytearray_eq(a, b)#
Return True if typed
bytearrayvalues are equal.Notes
Identity/len short-circuit plus
memcmp.
- picop.hot.bytearray_ne(a, b)#
Return True if typed
bytearrayvalues differ (not bytearray_eq). :type a:bytearray:param a: :type b:bytearray:param b:
- picop.hot.bytearray_contains(haystack, needle)#
Return True if
needleis found in typedhaystack.Notes
Mirrors
bytes_containssearch strategy on a typedbytearray.
- picop.hot.array_eq(a, b)#
Return True if typed
array.arrayvalues are equal.Notes
Compares typecode/len then
memcmp.
- picop.hot.array_ne(a, b)#
Return True if typed
array.arrayvalues differ (not array_eq). :type a:array:param a: :type b:array:param b:
- picop.hot.memoryview_eq(a, b)#
Return True if views are equal.
Notes
C-contiguous buffers use a
memcmpfast path; otherwise falls back to richcompare.- Parameters:
a (
memoryview)b (
memoryview)
- Return type:
- picop.hot.memoryview_ne(a, b)#
Return True if views differ.
Notes
Inverse of
memoryview_eq; same contig/richcompare rules.- Parameters:
a (
memoryview)b (
memoryview)
- Return type:
- picop.hot.str_eq(a, b)#
Return whether
a == b.Notes
Uses 1BYTE
memcmporPyUnicode_Comparedepending on kind.
- picop.hot.str_contains(haystack, needle)#
Return whether
needleis inhaystack.Notes
Uses 1BYTE
memchr/memmemorFinddepending on kind.
- picop.hot.ansi_wrap(prefix, text, suffix=None)#
Return
prefix + text + suffix.Notes
Default
suffixis the ANSI reset sequence.
- picop.hot.ansi_fg8(code)#
Return an 8-color foreground SGR for
code.Notes
Table hit for codes
30–37.