picop.cyunicode
Fast str UTF-8 and intern helpers.
-
class picop.cyunicode.UnicodeWriter
Bases: object
Build a string incrementally with CPython’s Unicode writer.
Notes
Slower than the plain-Python equivalent ''.join(parts) (Tier A 5.16x)
when the parts are already materialized; faster than s += p accumulation
(Tier A 0.74x) and cheaper in memory because no part list is built.
-
__enter__()
Return this writer.
- Return type:
UnicodeWriter
-
__exit__(exc_type, exc, tb)
Discard an unfinished writer when leaving the context.
- Parameters:
-
- Return type:
bool
-
discard()
Discard the writer buffer.
- Return type:
None
-
finish()
Finish writing and return the built string.
- Return type:
str
-
write(text)
Append a string to the writer.
- Parameters:
text (object)
- Return type:
None
-
write_ascii(text)
Append ASCII text.
- Parameters:
text (str)
- Return type:
None
-
write_char(ch)
Append a Unicode code point.
- Parameters:
ch (int)
- Return type:
None
-
write_repr(obj)
Append the representation of an object.
- Parameters:
obj (object)
- Return type:
None
-
write_substring(text, start=0, end=-1)
Append a substring.
- Parameters:
text (str)
start (int, default: 0)
end (int, default: -1)
- Return type:
None
-
write_utf8(data)
Append UTF-8 encoded bytes.
- Parameters:
data (bytes)
- Return type:
None
-
picop.cyunicode.uintern(s)
Intern s via PyUnicode_InternInPlace and return the canonical instance.
- Parameters:
s (str)
- Return type:
str
-
picop.cyunicode.unicode_eq(a, b)
Return True if a == b.
Notes
Thin alias of str_eq with the same semantics; prefer str_eq from
picop.cystr on value-op hot paths.
- Parameters:
-
- Return type:
bool
-
picop.cyunicode.uutf8_bytes(s)
Return owning UTF-8 bytes for s via PyUnicode_AsUTF8String.
Notes
Owning copy — safe to keep past the lifetime of s. Prefer this over
borrowed uutf8 (cimport-only) when you need a durable value.
- Parameters:
s (str)
- Return type:
bytes