removed pre-allocation of outputs

it doesn’t really seem to affect the performance anyway. vec.push() is pretty good
This commit is contained in:
kageru 2018-10-28 11:33:03 +01:00
parent 598e2cc0c5
commit 026db02c64
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -12,23 +12,11 @@ fn main() -> Result<()> {
renames.insert(split[0].to_string(), split[1].to_string());
}
// get the number of lines in the file so we can pre-allocate the array
let pf = fs::read_to_string("playlist.m3u").expect("unable to read");
let num_lines = pf.split("\n").collect::<Vec<&str>>().len() - 1;
let mut outputs: Vec<String> = vec![String::new(); num_lines];
//println!("{}", num_lines);
let mut outputs = Vec::new();
let pls_file = File::open("playlist.m3u")?;
let mut i = 0;
for entry in BufReader::new(pls_file).lines() {
let entry = entry?;
/*
match renames.get(&entry.to_string()) {
Some(line) => println!("found {}", line),
None => print!("")
}
*/
let new = renames.get(&entry).unwrap_or(&entry).to_string();
/*
if new != &entry {
@ -37,16 +25,10 @@ fn main() -> Result<()> {
println!("{}” remains unchanged", entry);
}
*/
outputs[i] = new;
i += 1;
outputs.push(new);
}
/*for s in outputs {
println!("{}", s);
}*/
let data = outputs.join("\n");
fs::write("playlist2.m3u", data).expect("unable to write");
//println!("{}", pf);
//println!("{}", renames.get(&"a string".to_string()).unwrap());
Ok(())
}