File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -2018,13 +2018,23 @@ impl<T> VecDeque<T> {
2018
2018
}
2019
2019
}
2020
2020
2021
+ // Safety: the following two methods require that the rotation amount
2022
+ // be less than half the length of the deque.
2023
+ //
2024
+ // `wrap_copy` requres that `min(x, cap() - x) + copy_len <= cap()`,
2025
+ // but than `min` is never more than half the capacity, regardless of x,
2026
+ // so it's sound to call here because we're calling with something
2027
+ // less than half the length, which is never above half the capacity.
2028
+
2021
2029
unsafe fn rotate_left_inner ( & mut self , mid : usize ) {
2030
+ debug_assert ! ( mid * 2 <= self . len( ) ) ;
2022
2031
self . wrap_copy ( self . head , self . tail , mid) ;
2023
2032
self . head = self . wrap_add ( self . head , mid) ;
2024
2033
self . tail = self . wrap_add ( self . tail , mid) ;
2025
2034
}
2026
2035
2027
2036
unsafe fn rotate_right_inner ( & mut self , k : usize ) {
2037
+ debug_assert ! ( k * 2 <= self . len( ) ) ;
2028
2038
self . head = self . wrap_sub ( self . head , k) ;
2029
2039
self . tail = self . wrap_sub ( self . tail , k) ;
2030
2040
self . wrap_copy ( self . tail , self . head , k) ;
You can’t perform that action at this time.
0 commit comments