Commit d0129f6
authored
[librt] Add minimal librt.strings.StringWriter class (experimental) (#20588)
It can be used to build a string from code points (via `append` method)
and strings (via `write`). It's similar to `BytesWriter`, but it has to
keep track of the kind of string being created (1/2/4 bytes per code
point).
I've optimized `append` but there are no mypyc primitives yet, so
performance is still bad. I'll add mypyc primitives in a follow-up PR
and do further optimizations as needed.
There is no `truncate` or `__setitem__`, unlike `BytesWriter`, since
these could require the recomputation of kind, and this would be
inefficient. My current thinking is that we won't support these.
I used LLM assist, especially for tests, but manually reviewed all
changes.1 parent c0b89be commit d0129f6
File tree
4 files changed
+792
-8
lines changed- mypyc
- lib-rt
- test-data
- mypy/typeshed/stubs/librt/librt
4 files changed
+792
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | | - | |
13 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
0 commit comments