Skip to content

Simplify the code in optimized extend#316

Merged
bluss merged 2 commits into
masterfrom
cleanup-extend
Jul 9, 2026
Merged

Simplify the code in optimized extend#316
bluss merged 2 commits into
masterfrom
cleanup-extend

Conversation

@bluss

@bluss bluss commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Simplify the code, revitalize the benchmarks (try to), while it should preserve the optimizations used.
Developed in the discussion of #315.

bluss added 2 commits July 9, 2026 15:00
Use std::hint::black_box (From Rust 1.6x), and use it more; this should
make the benchmarks at least a little bit more representative.
Keeping an eye on the benchmarks, simplify the optimization in
extend_from_iter; use a simpler scope guard. Use a counted index.
Previously there was a ZST special case which is not needed because:

`ptr` is a valid pointer for writing and `ptr.add(index)` still too;
`.write(elt)` consumes the element.

(Previous implementation: ptr was an out of bounds pointer for ZST.)

Benchmarks found to be sensitive to the order of predicates in
`if index == end && CHECK` which shouldn't be the case, but it was.

extend_from_iter: use only I: Iterator - reduce generics already in
`extend`.
@bluss bluss merged commit 2464b9b into master Jul 9, 2026
7 checks passed
@bluss bluss deleted the cleanup-extend branch July 9, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant