MathNya / umya-spreadsheet

A pure rust library for reading and writing spreadsheet files
MIT License
296 stars 47 forks source link

get_cell_by_column_and_row etc. function can be more efficient #32

Closed cstkingkey closed 2 years ago

cstkingkey commented 2 years ago

for example https://github.com/MathNya/umya-spreadsheet/blob/b9910d87a9c18ed1168916bb1762a209d801090a/src/structs/cells.rs#L101

when calling get_cell_by_column_and_row_mut to get a new cell, it will basically enumerate all cells two times.

I think that using hashmap with coordinate as the key to store the cells is better idea.

pub struct Cells {
    index: HashMap<(usize,usize), Cell>,
    default_cell_value: CellValue,
    default_style: Style,
}

pub fn get_cell_by_column_and_row_mut(&mut self, col: usize, row: usize) -> &mut Cell {
    let c = self.map.entry((col, row)).or_insert(Cell::default());
    c
}
MathNya commented 2 years ago

Thank you for your suggestion. This seems to be a more efficient way of processing. We will test it and if it is confirmed that there is no problem, we will address it in the next version update.

MathNya commented 2 years ago

The program has been corrected. Please obtain and review the latest version.