Skip to content

Commit 8d44bbc

Browse files
blussjturner314
andcommitted
append: Edits and clarifications in append comments
Co-authored-by: Jim Turner <[email protected]>
1 parent c1a5ceb commit 8d44bbc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/impl_owned_array.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ impl<A> Array<A, Ix2> {
8686
/// Appending automatically changes memory layout of the array so that it is appended to
8787
/// along the "growing axis".
8888
///
89-
/// Ensure appending is efficient by for example starting appending an empty array and
89+
/// Ensure appending is efficient by, for example, appending to an empty array and then
9090
/// always appending along the same axis. For rows, ndarray's default layout is efficient for
9191
/// appending.
9292
///
9393
/// Notice that an empty array (where it has an axis of length zero) is the simplest starting
94-
/// point. The amortized average complexity of the append is O(m) where *m* is the length of
94+
/// point. When repeatedly appending to a single axis, the amortized average complexity of each append is O(m), where *m* is the length of
9595
/// the row.
9696
///
9797
/// ```rust
@@ -123,12 +123,12 @@ impl<A> Array<A, Ix2> {
123123
/// Appending automatically changes memory layout of the array so that it is appended to
124124
/// along the "growing axis".
125125
///
126-
/// Ensure appending is efficient by for example starting appending an empty array and
126+
/// Ensure appending is efficient by, for example, appending to an empty array and then
127127
/// always appending along the same axis. For columns, column major ("F") memory layout is
128128
/// efficient for appending.
129129
///
130130
/// Notice that an empty array (where it has an axis of length zero) is the simplest starting
131-
/// point. The amortized average complexity of the append is O(m) where *m* is the length of
131+
/// point. When repeatedly appending to a single axis, the amortized average complexity of each append is O(m), where *m* is the length of
132132
/// the row.
133133
///
134134
/// ```rust
@@ -222,15 +222,16 @@ impl<A, D> Array<A, D>
222222
#[cold]
223223
fn drop_unreachable_elements_slow(mut self) -> OwnedRepr<A> {
224224
// "deconstruct" self; the owned repr releases ownership of all elements and we
225-
// and carry on with raw view methods
225+
// carry on with raw view methods
226226
let self_len = self.len();
227227
let data_len = self.data.len();
228228
let data_ptr = self.data.as_nonnull_mut().as_ptr();
229229

230230
let mut self_;
231231

232232
unsafe {
233-
// Safety: self.data releases ownership of the elements
233+
// Safety: self.data releases ownership of the elements. Any panics below this point
234+
// will result in leaking elements instead of double drops.
234235
self_ = self.raw_view_mut();
235236
self.data.set_len(0);
236237
}
@@ -430,7 +431,7 @@ impl<A, D> Array<A, D>
430431
}
431432
}
432433

433-
// array must be be "full" (have no exterior holes)
434+
// array must be be "full" (contiguous and have no exterior holes)
434435
if self.len() != self.data.len() {
435436
incompatible_layout = true;
436437
}
@@ -520,7 +521,7 @@ impl<A, D> Array<A, D>
520521
tail_view.shape(), tail_view.strides());
521522
}
522523

523-
// Keep track of currently filled lenght of `self.data` and update it
524+
// Keep track of currently filled length of `self.data` and update it
524525
// on scope exit (panic or loop finish).
525526
struct SetLenOnDrop<'a, A: 'a> {
526527
len: usize,
@@ -646,4 +647,3 @@ where
646647
}
647648
}
648649
}
649-

0 commit comments

Comments
 (0)