diff --git a/src/csv.rs b/src/csv.rs index 8fdd12f..8c3cc09 100644 --- a/src/csv.rs +++ b/src/csv.rs @@ -35,9 +35,9 @@ impl CsvParser { } fn parse_csv_line(&self) -> Vec { - let mut cell = String::new(); let mut in_quotes = false; let mut chars = self.buffer.chars().peekable(); + let mut cell = String::new(); let mut record = Vec::new(); while let Some(c) = chars.next() { @@ -69,6 +69,8 @@ impl CsvParser { /// Convert a two dimensional collection of Strings into a CSV compatible String pub fn export(records: &[Vec], output: &mut String) { output.clear(); + output.reserve(records.iter().map(|line| line.len() * 32).sum()); + for line in records { let mut first_cell = true; for cell in line { diff --git a/src/main.rs b/src/main.rs index 8df7ffa..e314b2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ fn main() { ); }, }; - let reader = BufReader::new(input_file); + let reader = BufReader::with_capacity(64 * 1024, input_file); let output_file = match File::create(&settings.output) { Ok(file) => file, @@ -77,7 +77,7 @@ fn main() { ); }, }; - let mut writer = BufWriter::new(output_file); + let mut writer = BufWriter::with_capacity(256 * 1024, output_file); let mut is_heading = true; let mut output = String::new(); diff --git a/src/process.rs b/src/process.rs index ae7aadf..0f09b28 100644 --- a/src/process.rs +++ b/src/process.rs @@ -9,8 +9,9 @@ use crate::{ pub fn run(input_line: &[String], output_config: &OutputConfig) -> Vec> { let mut new_lines = Vec::new(); let mut skip_line = false; + for items in &output_config.lines { - let mut line: Vec = Vec::new(); + let mut line: Vec = Vec::with_capacity(items.len()); for item in items { match item { Item::Cell(i, filters) => match input_line.get(*i) {