diff --git a/src/headparse.rs b/src/headparse.rs index 94911b4..c5ca663 100644 --- a/src/headparse.rs +++ b/src/headparse.rs @@ -11,7 +11,7 @@ use crate::SignalFormat; struct Record { name: String, seg_num: Option, - signal_count: u64, + signal_count: usize, sampling_freq: u64, counter_freq: Option, base_counter_val: Option, @@ -33,7 +33,7 @@ impl Record { } let name = args[0].to_string(); let seg_num: Option; - let sig_count: u64; + let sig_count: usize; let sampling_freq: u64; // Everything else is initialized with None, this is for sake of me not getting a stroke let mut counter_freq: Option = None; @@ -59,7 +59,7 @@ impl Record { } else { seg_num = None; } - match seg_sig[0].parse::() { + match seg_sig[0].parse::() { Ok(value) => { sig_count = value; } @@ -406,10 +406,13 @@ impl Header { Header { record: None, signal_specs: vec![] } } - /// Creates a Header from a supplied Record struct. Initializes the - /// signal_specs vector + /// Creates a Header from a supplied Record struct. + /// + /// Initializes the signal_specs vector with the correct capacity provided + /// by the record. fn from_record(record: Record) -> Header { - Header { record: Some(record), signal_specs: vec![] } + let capacity = record.signal_count; + Header { record: Some(record), signal_specs: Vec::with_capacity(capacity) } } fn add_signal_spec(&mut self, spec: SignalSpec) { @@ -432,8 +435,8 @@ pub fn parse_header(header_data: &str) -> Result { let header_lines: Vec<&str> = header_data.split("\n").collect(); let mut found_record: bool = false; let mut header: Header = Header::new(); - let mut specs_read: u64 = 0; - let mut specs_max: u64 = 0; + let mut specs_read: usize = 0; + let mut specs_max: usize = 0; for line in header_lines { // Ignore commented lines if line.starts_with("#") {