mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 22:07:55 +02:00
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.  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:
@ -17,8 +17,8 @@ use nu_protocol::{
|
||||
Signals, TableMode, ValueIterator,
|
||||
};
|
||||
use nu_table::{
|
||||
common::configure_table, CollapsedTable, ExpandedTable, JustTable, NuRecordsValue, NuTable,
|
||||
StringResult, TableOpts, TableOutput,
|
||||
common::configure_table, CollapsedTable, ExpandedTable, JustTable, NuTable, StringResult,
|
||||
TableOpts, TableOutput,
|
||||
};
|
||||
use nu_utils::{get_ls_colors, terminal_size};
|
||||
|
||||
@ -609,7 +609,7 @@ fn build_table_kv(
|
||||
span: Span,
|
||||
) -> StringResult {
|
||||
match table_view {
|
||||
TableView::General => JustTable::kv_table(&record, opts),
|
||||
TableView::General => JustTable::kv_table(record, opts),
|
||||
TableView::Expanded {
|
||||
limit,
|
||||
flatten,
|
||||
@ -645,7 +645,7 @@ fn build_table_batch(
|
||||
}
|
||||
|
||||
match view {
|
||||
TableView::General => JustTable::table(&vals, opts),
|
||||
TableView::General => JustTable::table(vals, opts),
|
||||
TableView::Expanded {
|
||||
limit,
|
||||
flatten,
|
||||
@ -1090,9 +1090,9 @@ fn create_empty_placeholder(
|
||||
return String::new();
|
||||
}
|
||||
|
||||
let cell = NuRecordsValue::new(format!("empty {}", value_type_name));
|
||||
let data = vec![vec![cell]];
|
||||
let mut table = NuTable::from(data);
|
||||
let cell = format!("empty {}", value_type_name);
|
||||
let mut table = NuTable::new(1, 1);
|
||||
table.insert((0, 0), cell);
|
||||
table.set_data_style(TextStyle::default().dimmed());
|
||||
let mut out = TableOutput::from_table(table, false, false);
|
||||
|
||||
|
Reference in New Issue
Block a user