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:
parent
598e2cc0c5
commit
026db02c64
22
src/main.rs
22
src/main.rs
|
@ -12,23 +12,11 @@ fn main() -> Result<()> {
|
||||||
renames.insert(split[0].to_string(), split[1].to_string());
|
renames.insert(split[0].to_string(), split[1].to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut outputs = Vec::new();
|
||||||
// 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 pls_file = File::open("playlist.m3u")?;
|
let pls_file = File::open("playlist.m3u")?;
|
||||||
let mut i = 0;
|
|
||||||
for entry in BufReader::new(pls_file).lines() {
|
for entry in BufReader::new(pls_file).lines() {
|
||||||
let entry = entry?;
|
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();
|
let new = renames.get(&entry).unwrap_or(&entry).to_string();
|
||||||
/*
|
/*
|
||||||
if new != &entry {
|
if new != &entry {
|
||||||
|
@ -37,16 +25,10 @@ fn main() -> Result<()> {
|
||||||
println!("“{}” remains unchanged", entry);
|
println!("“{}” remains unchanged", entry);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
outputs[i] = new;
|
outputs.push(new);
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
/*for s in outputs {
|
|
||||||
println!("{}", s);
|
|
||||||
}*/
|
|
||||||
let data = outputs.join("\n");
|
let data = outputs.join("\n");
|
||||||
fs::write("playlist2.m3u", data).expect("unable to write");
|
fs::write("playlist2.m3u", data).expect("unable to write");
|
||||||
//println!("{}", pf);
|
|
||||||
//println!("{}", renames.get(&"a string".to_string()).unwrap());
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user