reuse allocated string for timeseries read

This commit is contained in:
Daniel Bauer
2018-10-14 11:53:44 +02:00
parent f8b073f120
commit 6d4160cee6

View File

@@ -129,7 +129,7 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
eprintln!("Failed to read sample data from {}. {}", window_file, x); eprintln!("Failed to read sample data from {}. {}", window_file, x);
process::exit(1) process::exit(1)
}); });
let buf = BufReader::new(&f); let mut buf = BufReader::new(&f);
// total number of bins is the product of all dimensions length // total number of bins is the product of all dimensions length
let total_bins = cfg.num_bins.iter().fold(1, |s, &x| { s*x }); let total_bins = cfg.num_bins.iter().fold(1, |s, &x| { s*x });
@@ -141,9 +141,9 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
}).collect(); }).collect();
// read and parse each timeseries line // read and parse each timeseries line
for l in buf.lines() { let mut line = String::new();
let line = l.unwrap(); while buf.read_line(&mut line).unwrap() > 0 {
{
// skip comments and empty lines // skip comments and empty lines
if line.starts_with("#") || line.starts_with("@") || line.len() == 0 { if line.starts_with("#") || line.starts_with("@") || line.len() == 0 {
continue; continue;
@@ -166,6 +166,8 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
hist[index] += 1.0; hist[index] += 1.0;
} }
} }
line.clear();
}
let num_points: f64 = hist.iter().sum(); let num_points: f64 = hist.iter().sum();
if num_points == 0.0 { if num_points == 0.0 {