Skip to content

Commit 531ea05

Browse files
committed
1 parent 71d242f commit 531ea05

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/lib.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<T> Vc<T> {
129129
///
130130
/// let vector: Vc<u32> = Vc::new();
131131
/// ```
132-
pub fn new() -> Self {
132+
pub const fn new() -> Self {
133133
Self {
134134
new_tail: VecDeque::new(),
135135
old_head: None,
@@ -658,7 +658,7 @@ impl<T> Vc<T> {
658658
///
659659
/// ```
660660
/// use atone::Vc;
661-
/// let mut vector = Vc::new();
661+
/// let mut vector = Vc::with_capacity(3);
662662
///
663663
/// vector.push(0);
664664
/// vector.push(1);
@@ -1965,8 +1965,8 @@ mod tests {
19651965

19661966
#[test]
19671967
fn test_zero_capacities() {
1968-
assert_eq!(VecDeque::<i32>::with_capacity(0).capacity(), 1);
1969-
assert_eq!(Vc::<i32>::with_capacity(0).capacity(), 1);
1968+
assert_eq!(VecDeque::<i32>::with_capacity(0).capacity(), 0);
1969+
assert_eq!(Vc::<i32>::with_capacity(0).capacity(), 0);
19701970
}
19711971

19721972
#[test]
@@ -2013,7 +2013,11 @@ mod tests {
20132013
// fourth push will split and migrate all elements
20142014
assert!(!m.is_atoning());
20152015
m.push(4);
2016-
// capacity should now be doubled
2016+
// capacity should now be increased
2017+
assert_eq!(m.capacity(), 5);
2018+
// we hard-code what it grows to just to make life easier below
2019+
let n = m.new_tail.len();
2020+
m.new_tail.reserve_exact(7 - n);
20172021
assert_eq!(m.capacity(), 7);
20182022
// and there should be no leftovers
20192023
assert!(!m.is_atoning());
@@ -2034,7 +2038,11 @@ mod tests {
20342038

20352039
// next push will split, and move some, but not all (since R < old.len())
20362040
m.push(8);
2037-
// capacity should now be doubled
2041+
// capacity should now increase again
2042+
assert_eq!(m.capacity(), 11);
2043+
// and again we fix the new capacity to make the code below easier
2044+
let n = m.new_tail.len();
2045+
m.new_tail.reserve_exact(15 - n);
20382046
assert_eq!(m.capacity(), 15);
20392047
// and there should be leftovers
20402048
assert!(m.is_atoning());
@@ -2335,13 +2343,13 @@ mod tests {
23352343
#[test]
23362344
fn test_iterate() {
23372345
let mut vs = Vc::with_capacity(4);
2338-
for i in 0..32 {
2346+
for i in 0..=36 {
23392347
vs.push(i * 2);
23402348
}
23412349
assert!(vs.is_atoning());
2342-
assert_eq!(vs.len(), 32);
2350+
assert_eq!(vs.len(), 37);
23432351

2344-
assert!(vs.iter().copied().eq((0..32).map(|v| v * 2)));
2352+
assert!(vs.iter().copied().eq((0..=36).map(|v| v * 2)));
23452353
}
23462354

23472355
#[test]
@@ -2437,7 +2445,7 @@ mod tests {
24372445

24382446
#[test]
24392447
fn test_index() {
2440-
let mut vs = Vc::new();
2448+
let mut vs = Vc::with_capacity(7);
24412449

24422450
for i in 1..=8 {
24432451
vs.push(i);

0 commit comments

Comments
 (0)