Skip to content

Commit

Permalink
added more pre-allocations
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Wilkowski <[email protected]>
  • Loading branch information
dominikwilkowski committed Dec 4, 2024
1 parent 294a56d commit 18655ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ impl<R: BufRead> CsvParser<R> {
}

fn parse_csv_line(&self) -> Vec<String> {
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() {
Expand Down Expand Up @@ -69,6 +69,8 @@ impl<R: BufRead> CsvParser<R> {
/// Convert a two dimensional collection of Strings into a CSV compatible String
pub fn export(records: &[Vec<String>], 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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use crate::{
pub fn run(input_line: &[String], output_config: &OutputConfig) -> Vec<Vec<String>> {
let mut new_lines = Vec::new();
let mut skip_line = false;

for items in &output_config.lines {
let mut line: Vec<String> = Vec::new();
let mut line: Vec<String> = Vec::with_capacity(items.len());
for item in items {
match item {
Item::Cell(i, filters) => match input_line.get(*i) {
Expand Down

0 comments on commit 18655ac

Please sign in to comment.