@@ -129,7 +129,7 @@ impl<T> Vc<T> {
129
129
///
130
130
/// let vector: Vc<u32> = Vc::new();
131
131
/// ```
132
- pub fn new ( ) -> Self {
132
+ pub const fn new ( ) -> Self {
133
133
Self {
134
134
new_tail : VecDeque :: new ( ) ,
135
135
old_head : None ,
@@ -658,7 +658,7 @@ impl<T> Vc<T> {
658
658
///
659
659
/// ```
660
660
/// use atone::Vc;
661
- /// let mut vector = Vc::new( );
661
+ /// let mut vector = Vc::with_capacity(3 );
662
662
///
663
663
/// vector.push(0);
664
664
/// vector.push(1);
@@ -1965,8 +1965,8 @@ mod tests {
1965
1965
1966
1966
#[ test]
1967
1967
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 ) ;
1970
1970
}
1971
1971
1972
1972
#[ test]
@@ -2013,7 +2013,11 @@ mod tests {
2013
2013
// fourth push will split and migrate all elements
2014
2014
assert ! ( !m. is_atoning( ) ) ;
2015
2015
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) ;
2017
2021
assert_eq ! ( m. capacity( ) , 7 ) ;
2018
2022
// and there should be no leftovers
2019
2023
assert ! ( !m. is_atoning( ) ) ;
@@ -2034,7 +2038,11 @@ mod tests {
2034
2038
2035
2039
// next push will split, and move some, but not all (since R < old.len())
2036
2040
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) ;
2038
2046
assert_eq ! ( m. capacity( ) , 15 ) ;
2039
2047
// and there should be leftovers
2040
2048
assert ! ( m. is_atoning( ) ) ;
@@ -2335,13 +2343,13 @@ mod tests {
2335
2343
#[ test]
2336
2344
fn test_iterate ( ) {
2337
2345
let mut vs = Vc :: with_capacity ( 4 ) ;
2338
- for i in 0 ..32 {
2346
+ for i in 0 ..= 36 {
2339
2347
vs. push ( i * 2 ) ;
2340
2348
}
2341
2349
assert ! ( vs. is_atoning( ) ) ;
2342
- assert_eq ! ( vs. len( ) , 32 ) ;
2350
+ assert_eq ! ( vs. len( ) , 37 ) ;
2343
2351
2344
- assert ! ( vs. iter( ) . copied( ) . eq( ( 0 ..32 ) . map( |v| v * 2 ) ) ) ;
2352
+ assert ! ( vs. iter( ) . copied( ) . eq( ( 0 ..= 36 ) . map( |v| v * 2 ) ) ) ;
2345
2353
}
2346
2354
2347
2355
#[ test]
@@ -2437,7 +2445,7 @@ mod tests {
2437
2445
2438
2446
#[ test]
2439
2447
fn test_index ( ) {
2440
- let mut vs = Vc :: new ( ) ;
2448
+ let mut vs = Vc :: with_capacity ( 7 ) ;
2441
2449
2442
2450
for i in 1 ..=8 {
2443
2451
vs. push ( i) ;
0 commit comments