Skip to content

Commit c9dd195

Browse files
committed
append: Add comment explaining the SetLenOnDrop optimization
Benchmarks (append benchmarks) show that this is a worthwhile optimization, and that plain self.data.set_len() in the loop performs worse.
1 parent 59013cd commit c9dd195

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/impl_owned_array.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,9 @@ impl<A, D> Array<A, D>
537537
}
538538

539539
// Keep track of currently filled length of `self.data` and update it
540-
// on scope exit (panic or loop finish).
540+
// on scope exit (panic or loop finish). This "indirect" way to
541+
// write the length is used to help the compiler, the len store to self.data may
542+
// otherwise be mistaken to alias with other stores in the loop.
541543
struct SetLenOnDrop<'a, A: 'a> {
542544
len: usize,
543545
data: &'a mut OwnedRepr<A>,

0 commit comments

Comments
 (0)