From d7dc85d80e7ee95c03d6028300887bc2fceffbe6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 20 Jun 2015 13:33:25 +0200 Subject: [PATCH] Use slice::from_raw_parts to simplify command_line_init. --- ports/cef/command_line.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ports/cef/command_line.rs b/ports/cef/command_line.rs index 9af3709f4cd..7f70c77bafa 100644 --- a/ports/cef/command_line.rs +++ b/ports/cef/command_line.rs @@ -32,12 +32,11 @@ fn command_line_new() -> *mut command_line_t { pub fn command_line_init(argc: c_int, argv: *const *const u8) { unsafe { - let mut a: Vec = vec!(); - for i in 0..(argc as usize) { - let slice = ffi::CStr::from_ptr(*argv.offset(i as isize) as *const c_char); - let s = str::from_utf8(slice.to_bytes()).unwrap(); - a.push(s.to_owned()); - } + let args = slice::from_raw_parts(argv, argc as usize); + let a = args.iter().map(|&arg| { + let slice = ffi::CStr::from_ptr(arg as *const c_char); + str::from_utf8(slice.to_bytes()).unwrap().to_owned() + }).collect(); let cl = command_line_new(); (*cl).argc = argc; (*cl).argv = a;