Skip to content

Commit f141c1b

Browse files
committed
perf: excel microoptimize hot loop by using enumerate instead of manual counter
1 parent 2d26f79 commit f141c1b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/cmd/excel.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,15 +1015,13 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
10151015
let mut formatted_date = String::new();
10161016

10171017
let mut processed_chunk: Vec<csv::StringRecord> = Vec::with_capacity(chunk_size);
1018-
let mut col_idx: u32;
10191018

10201019
let mut cell_formula;
10211020
let mut itoa_buf = itoa::Buffer::new();
10221021
let mut ryu_buf = ryu::Buffer::new();
10231022

10241023
for (row_idx, row) in chunk {
1025-
col_idx = 0;
1026-
for cell in *row {
1024+
for (col_idx, cell) in row.iter().enumerate() {
10271025
match *cell {
10281026
Data::Empty => record.push_field(""),
10291027
Data::String(ref s) => record.push_field(s),
@@ -1101,7 +1099,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
11011099
write!(error_buffer, "{e}").unwrap();
11021100
} else {
11031101
cell_formula = sheet_formulas
1104-
.get_value((*row_idx, col_idx))
1102+
.get_value((*row_idx, col_idx as u32))
11051103
.unwrap_or(&formula_get_value_error);
11061104
if error_format == ErrorFormat::Formula {
11071105
write!(error_buffer, "#={cell_formula}").unwrap();
@@ -1113,7 +1111,6 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
11131111
record.push_field(error_buffer.as_str());
11141112
},
11151113
}
1116-
col_idx += 1;
11171114
}
11181115

11191116
if trim {

0 commit comments

Comments
 (0)