@@ -55,7 +55,7 @@ extern crate core as std;
55
55
extern crate alloc;
56
56
57
57
#[ cfg( feature = "use_alloc" ) ]
58
- use alloc:: { string:: String , vec:: Vec } ;
58
+ use alloc:: { collections :: VecDeque , string:: String , vec:: Vec } ;
59
59
60
60
pub use either:: Either ;
61
61
@@ -72,6 +72,8 @@ use std::fmt::Write;
72
72
use std:: hash:: Hash ;
73
73
use std:: iter:: { once, IntoIterator } ;
74
74
#[ cfg( feature = "use_alloc" ) ]
75
+ type VecDequeIntoIter < T > = alloc:: collections:: vec_deque:: IntoIter < T > ;
76
+ #[ cfg( feature = "use_alloc" ) ]
75
77
type VecIntoIter < T > = alloc:: vec:: IntoIter < T > ;
76
78
use std:: iter:: FromIterator ;
77
79
@@ -3153,14 +3155,14 @@ pub trait Itertools: Iterator {
3153
3155
/// `.rev().take(n).rev()` to have a similar result (lazy and non-allocating)
3154
3156
/// without consuming the entire iterator.
3155
3157
#[ cfg( feature = "use_alloc" ) ]
3156
- fn tail ( self , n : usize ) -> VecIntoIter < Self :: Item >
3158
+ fn tail ( self , n : usize ) -> VecDequeIntoIter < Self :: Item >
3157
3159
where
3158
3160
Self : Sized ,
3159
3161
{
3160
3162
match n {
3161
3163
0 => {
3162
3164
self . last ( ) ;
3163
- Vec :: new ( )
3165
+ VecDeque :: new ( )
3164
3166
}
3165
3167
1 => self . last ( ) . into_iter ( ) . collect ( ) ,
3166
3168
_ => {
@@ -3177,7 +3179,8 @@ pub trait Itertools: Iterator {
3177
3179
i + 1
3178
3180
}
3179
3181
} ) ;
3180
- // Respect the insertion order.
3182
+ // Respect the insertion order, efficiently.
3183
+ let mut data = VecDeque :: from ( data) ;
3181
3184
data. rotate_left ( idx) ;
3182
3185
data
3183
3186
}
0 commit comments