mypy
38c3fcb9 - [mypyc] Use memory copy for vec init and extend using buffer protocol (#21349)

Commit
57 days ago
[mypyc] Use memory copy for vec init and extend using buffer protocol (#21349) For vecs with value item types, use the buffer protocol for fast bulk item access during construction and `extend()`. Previously each item had to be boxed and then unboxed, which was inefficient. This works with `bytes` and `array.array`, for example, and should also work with NumPy arrays (didn't test with NumPy though). Examples where this matters include `v = vec[u8](b"foo")` and `v = extend(v, b"bar")`. Since the `bool` item type uses a non-standard encoding, it's not supported. We can make `bytes` even faster by adding further specialization. I'll do this in a follow-up PR. I used coding agent assist with small incremental changes.
Author
Parents
Loading