nu-table/ 1 refactoring + a few optimizations + small fix (#15653)

- A few days back I've got this idea regarding recalculus of width.
Now it calculates step by step.
So 1 loop over all data was removed.
All though there's full recalculation in case of `header_on_border`
😞 (can be fixed..... but I decided to be short)

In perfect world it also shall be refactored ......

- Also have done small refactoring to switch build table from
`Vec<Vec<_>>>` to table itself. To hide internals (kind of still there's
things which I don't like).
It touched the `--expand` algorithm lightly you can see the tests
changes.

- And when doing that noticed one more opportunity, to remove HashMap
usage and directly use `tabled::ColoredConfig`. Which reduces copy
operations and allocations.

- And fixed a small issue where trailing column being using deleted
column styles.


![image](https://github.com/user-attachments/assets/19b09dba-c688-4e91-960a-e11ed11fd275)

To conclude optimizations;
I did small testing and it's not slower.
But I didn't get the faster results either.
But I believe it must be faster well in all cases, I think maybe bigger
tables must be tested.
Maybe someone could have a few runs to compare performance.

cc: @fdncred
This commit is contained in:
Maxim Zhiburt
2025-05-01 17:43:30 +03:00
committed by GitHub
parent 60e9f469af
commit deca337a56
7 changed files with 821 additions and 692 deletions

View File

@ -21,10 +21,12 @@ fn main() {
let headers = to_cell_info_vec(&table_headers);
let rows = to_cell_info_vec(&row_data);
let mut rows = vec![rows; 3];
rows.insert(0, headers);
let mut table = NuTable::new(4, 3);
table.set_row(0, headers);
let mut table = NuTable::from(rows);
for i in 0..3 {
table.set_row(i + 1, rows.clone());
}
table.set_data_style(TextStyle::basic_left());
table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));