@@ -15,7 +15,7 @@ use sys::windows::os::current_exe;
15
15
use sys:: c;
16
16
use ffi:: OsString ;
17
17
use fmt;
18
- use collections :: VecDeque ;
18
+ use vec ;
19
19
use core:: iter;
20
20
use slice;
21
21
use path:: PathBuf ;
@@ -43,19 +43,19 @@ pub fn args() -> Args {
43
43
/// GUI applications add a bunch of overhead, even if no windows are drawn. See
44
44
/// <https://randomascii.wordpress.com/2018/12/03/a-not-called-function-can-cause-a-5x-slowdown/>.
45
45
unsafe fn parse_lp_cmd_line < F : Fn ( ) -> OsString > ( lp_cmd_line : * const u16 , exe_name : F )
46
- -> VecDeque < OsString > {
46
+ -> vec :: IntoIter < OsString > {
47
47
const BACKSLASH : u16 = '\\' as u16 ;
48
48
const QUOTE : u16 = '"' as u16 ;
49
49
const TAB : u16 = '\t' as u16 ;
50
50
const SPACE : u16 = ' ' as u16 ;
51
51
let mut in_quotes = false ;
52
52
let mut was_in_quotes = false ;
53
53
let mut backslash_count: usize = 0 ;
54
- let mut ret_val = VecDeque :: new ( ) ;
54
+ let mut ret_val = Vec :: new ( ) ;
55
55
let mut cur = Vec :: new ( ) ;
56
56
if lp_cmd_line. is_null ( ) || * lp_cmd_line == 0 {
57
- ret_val. push_back ( exe_name ( ) ) ;
58
- return ret_val;
57
+ ret_val. push ( exe_name ( ) ) ;
58
+ return ret_val. into_iter ( ) ;
59
59
}
60
60
let mut i = 0 ;
61
61
// The executable name at the beginning is special.
@@ -66,16 +66,16 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
66
66
loop {
67
67
i += 1 ;
68
68
if * lp_cmd_line. offset ( i) == 0 {
69
- ret_val. push_back ( OsString :: from_wide (
69
+ ret_val. push ( OsString :: from_wide (
70
70
slice:: from_raw_parts ( lp_cmd_line. offset ( 1 ) , i as usize - 1 )
71
71
) ) ;
72
- return ret_val;
72
+ return ret_val. into_iter ( ) ;
73
73
}
74
74
if * lp_cmd_line. offset ( i) == QUOTE {
75
75
break ;
76
76
}
77
77
}
78
- ret_val. push_back ( OsString :: from_wide (
78
+ ret_val. push ( OsString :: from_wide (
79
79
slice:: from_raw_parts ( lp_cmd_line. offset ( 1 ) , i as usize - 1 )
80
80
) ) ;
81
81
i += 1 ;
@@ -86,25 +86,25 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
86
86
// will consider the first argument to be an empty string. Excess whitespace at the
87
87
// end of lpCmdLine is ignored."
88
88
0 ...SPACE => {
89
- ret_val. push_back ( OsString :: new ( ) ) ;
89
+ ret_val. push ( OsString :: new ( ) ) ;
90
90
i += 1 ;
91
91
} ,
92
- // The executable name ends at the next quote mark ,
92
+ // The executable name ends at the next whitespace ,
93
93
// no matter what.
94
94
_ => {
95
95
loop {
96
96
i += 1 ;
97
97
if * lp_cmd_line. offset ( i) == 0 {
98
- ret_val. push_back ( OsString :: from_wide (
98
+ ret_val. push ( OsString :: from_wide (
99
99
slice:: from_raw_parts ( lp_cmd_line, i as usize )
100
100
) ) ;
101
- return ret_val;
101
+ return ret_val. into_iter ( ) ;
102
102
}
103
103
if let 0 ...SPACE = * lp_cmd_line. offset ( i) {
104
104
break ;
105
105
}
106
106
}
107
- ret_val. push_back ( OsString :: from_wide (
107
+ ret_val. push ( OsString :: from_wide (
108
108
slice:: from_raw_parts ( lp_cmd_line, i as usize )
109
109
) ) ;
110
110
i += 1 ;
@@ -138,7 +138,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
138
138
SPACE | TAB if !in_quotes => {
139
139
cur. extend ( iter:: repeat ( b'\\' as u16 ) . take ( backslash_count) ) ;
140
140
if !cur. is_empty ( ) || was_in_quotes {
141
- ret_val. push_back ( OsString :: from_wide ( & cur[ ..] ) ) ;
141
+ ret_val. push ( OsString :: from_wide ( & cur[ ..] ) ) ;
142
142
cur. truncate ( 0 ) ;
143
143
}
144
144
backslash_count = 0 ;
@@ -148,7 +148,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
148
148
cur. extend ( iter:: repeat ( b'\\' as u16 ) . take ( backslash_count) ) ;
149
149
// include empty quoted strings at the end of the arguments list
150
150
if !cur. is_empty ( ) || was_in_quotes || in_quotes {
151
- ret_val. push_back ( OsString :: from_wide ( & cur[ ..] ) ) ;
151
+ ret_val. push ( OsString :: from_wide ( & cur[ ..] ) ) ;
152
152
}
153
153
break ;
154
154
}
@@ -161,11 +161,11 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
161
161
}
162
162
i += 1 ;
163
163
}
164
- ret_val
164
+ ret_val. into_iter ( )
165
165
}
166
166
167
167
pub struct Args {
168
- parsed_args_list : VecDeque < OsString > ,
168
+ parsed_args_list : vec :: IntoIter < OsString > ,
169
169
}
170
170
171
171
pub struct ArgsInnerDebug < ' a > {
@@ -176,7 +176,7 @@ impl<'a> fmt::Debug for ArgsInnerDebug<'a> {
176
176
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
177
177
f. write_str ( "[" ) ?;
178
178
let mut first = true ;
179
- for i in & self . args . parsed_args_list {
179
+ for i in self . args . parsed_args_list . clone ( ) {
180
180
if !first {
181
181
f. write_str ( ", " ) ?;
182
182
}
@@ -199,14 +199,12 @@ impl Args {
199
199
200
200
impl Iterator for Args {
201
201
type Item = OsString ;
202
- fn next ( & mut self ) -> Option < OsString > { self . parsed_args_list . pop_front ( ) }
203
- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
204
- ( self . parsed_args_list . len ( ) , Some ( self . parsed_args_list . len ( ) ) )
205
- }
202
+ fn next ( & mut self ) -> Option < OsString > { self . parsed_args_list . next ( ) }
203
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . parsed_args_list . size_hint ( ) }
206
204
}
207
205
208
206
impl DoubleEndedIterator for Args {
209
- fn next_back ( & mut self ) -> Option < OsString > { self . parsed_args_list . pop_back ( ) }
207
+ fn next_back ( & mut self ) -> Option < OsString > { self . parsed_args_list . next_back ( ) }
210
208
}
211
209
212
210
impl ExactSizeIterator for Args {
0 commit comments