Skip to content

Commit 08fbbbd

Browse files
committed
Fix nitpicks
Switch to vec::IntoIter as our backing double-ended iterator. Fix incorrect comment.
1 parent 81de5d9 commit 08fbbbd

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/libstd/sys/windows/args.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use sys::windows::os::current_exe;
1515
use sys::c;
1616
use ffi::OsString;
1717
use fmt;
18-
use collections::VecDeque;
18+
use vec;
1919
use core::iter;
2020
use slice;
2121
use path::PathBuf;
@@ -43,19 +43,19 @@ pub fn args() -> Args {
4343
/// GUI applications add a bunch of overhead, even if no windows are drawn. See
4444
/// <https://randomascii.wordpress.com/2018/12/03/a-not-called-function-can-cause-a-5x-slowdown/>.
4545
unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_name: F)
46-
-> VecDeque<OsString> {
46+
-> vec::IntoIter<OsString> {
4747
const BACKSLASH: u16 = '\\' as u16;
4848
const QUOTE: u16 = '"' as u16;
4949
const TAB: u16 = '\t' as u16;
5050
const SPACE: u16 = ' ' as u16;
5151
let mut in_quotes = false;
5252
let mut was_in_quotes = false;
5353
let mut backslash_count: usize = 0;
54-
let mut ret_val = VecDeque::new();
54+
let mut ret_val = Vec::new();
5555
let mut cur = Vec::new();
5656
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();
5959
}
6060
let mut i = 0;
6161
// 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
6666
loop {
6767
i += 1;
6868
if *lp_cmd_line.offset(i) == 0 {
69-
ret_val.push_back(OsString::from_wide(
69+
ret_val.push(OsString::from_wide(
7070
slice::from_raw_parts(lp_cmd_line.offset(1), i as usize - 1)
7171
));
72-
return ret_val;
72+
return ret_val.into_iter();
7373
}
7474
if *lp_cmd_line.offset(i) == QUOTE {
7575
break;
7676
}
7777
}
78-
ret_val.push_back(OsString::from_wide(
78+
ret_val.push(OsString::from_wide(
7979
slice::from_raw_parts(lp_cmd_line.offset(1), i as usize - 1)
8080
));
8181
i += 1;
@@ -86,25 +86,25 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
8686
// will consider the first argument to be an empty string. Excess whitespace at the
8787
// end of lpCmdLine is ignored."
8888
0...SPACE => {
89-
ret_val.push_back(OsString::new());
89+
ret_val.push(OsString::new());
9090
i += 1;
9191
},
92-
// The executable name ends at the next quote mark,
92+
// The executable name ends at the next whitespace,
9393
// no matter what.
9494
_ => {
9595
loop {
9696
i += 1;
9797
if *lp_cmd_line.offset(i) == 0 {
98-
ret_val.push_back(OsString::from_wide(
98+
ret_val.push(OsString::from_wide(
9999
slice::from_raw_parts(lp_cmd_line, i as usize)
100100
));
101-
return ret_val;
101+
return ret_val.into_iter();
102102
}
103103
if let 0...SPACE = *lp_cmd_line.offset(i) {
104104
break;
105105
}
106106
}
107-
ret_val.push_back(OsString::from_wide(
107+
ret_val.push(OsString::from_wide(
108108
slice::from_raw_parts(lp_cmd_line, i as usize)
109109
));
110110
i += 1;
@@ -138,7 +138,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
138138
SPACE | TAB if !in_quotes => {
139139
cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
140140
if !cur.is_empty() || was_in_quotes {
141-
ret_val.push_back(OsString::from_wide(&cur[..]));
141+
ret_val.push(OsString::from_wide(&cur[..]));
142142
cur.truncate(0);
143143
}
144144
backslash_count = 0;
@@ -148,7 +148,7 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
148148
cur.extend(iter::repeat(b'\\' as u16).take(backslash_count));
149149
// include empty quoted strings at the end of the arguments list
150150
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[..]));
152152
}
153153
break;
154154
}
@@ -161,11 +161,11 @@ unsafe fn parse_lp_cmd_line<F: Fn() -> OsString>(lp_cmd_line: *const u16, exe_na
161161
}
162162
i += 1;
163163
}
164-
ret_val
164+
ret_val.into_iter()
165165
}
166166

167167
pub struct Args {
168-
parsed_args_list: VecDeque<OsString>,
168+
parsed_args_list: vec::IntoIter<OsString>,
169169
}
170170

171171
pub struct ArgsInnerDebug<'a> {
@@ -176,7 +176,7 @@ impl<'a> fmt::Debug for ArgsInnerDebug<'a> {
176176
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
177177
f.write_str("[")?;
178178
let mut first = true;
179-
for i in &self.args.parsed_args_list {
179+
for i in self.args.parsed_args_list.clone() {
180180
if !first {
181181
f.write_str(", ")?;
182182
}
@@ -199,14 +199,12 @@ impl Args {
199199

200200
impl Iterator for Args {
201201
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() }
206204
}
207205

208206
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() }
210208
}
211209

212210
impl ExactSizeIterator for Args {

0 commit comments

Comments
 (0)