oxc-project / oxc-project/backlog
Optimize `Vec::split_off`
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 7
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Now that we have our own Vec implementation, we can add some APIs which were previously impossible.
Vec::split_at can convert a Vec into 2 x Vecs, without copying any data or making any allocations.
let original_len = vec.len();
let original_capacity = vec.capacity();
let original_ptr = vec.as_ptr();
// `split_at` returns `None` if `vec.len() < 2`
let (vec1, vec2) = vec.split_at(2).unwrap();
assert!(vec1.len() == 2);
assert!(vec1.capacity() == 2);
assert!(vec2.len() == original_len - 2);
assert!(vec2.capacity() == original_capacity - 2);
// `vec1` and `vec2` point to chunks of the original `vec`
assert!(vec1.as_ptr() == original_ptr);
assert!(vec2.as_ptr() == original_ptr.add(2));
This would be useful in various places in transformer where we currently have to allocate new Vecs and copy data around. e.g. https://github.com/oxc-project/oxc/pull/10434#issuecomment-2809350194
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the repository's own Vec implementation and the existing split_at entry point. Use the stated behavior as the acceptance criteria: two Vecs should share the original allocation without copying, with the specified lengths, capacities, and pointers; add or run focused tests for those properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100