mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-25 14:10:31 +00:00
699c2d7c8d
- Rewrote the line / span rendering code to take into account how multi-byte / wide emoji characters are truncated when rendering into areas that cannot accommodate them in the available space - Added comprehensive coverage over the edge cases - Adds a benchmark to ensure perf Fixes: https://github.com/ratatui-org/ratatui/issues/1032 Co-authored-by: EdJoPaTo <rfc-conform-git-commit-email@funny-long-domain-label-everyone-hates-as-it-is-too-long.edjopato.de> Co-authored-by: EdJoPaTo <github@edjopato.de>
39 lines
1.1 KiB
Rust
39 lines
1.1 KiB
Rust
use std::hint::black_box;
|
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
use ratatui::{
|
|
buffer::Buffer,
|
|
layout::{Alignment, Rect},
|
|
style::Stylize,
|
|
text::Line,
|
|
widgets::Widget,
|
|
};
|
|
|
|
fn line_render(criterion: &mut Criterion) {
|
|
for alignment in [Alignment::Left, Alignment::Center, Alignment::Right] {
|
|
let mut group = criterion.benchmark_group(format!("line_render/{alignment}"));
|
|
group.sample_size(1000);
|
|
|
|
let line = &Line::from(vec![
|
|
"This".red(),
|
|
" ".green(),
|
|
"is".italic(),
|
|
" ".blue(),
|
|
"SPARTA!!".bold(),
|
|
])
|
|
.alignment(alignment);
|
|
|
|
for width in [0, 3, 4, 6, 7, 10, 42] {
|
|
let area = Rect::new(0, 0, width, 1);
|
|
|
|
group.bench_function(width.to_string(), |bencher| {
|
|
let mut buffer = Buffer::empty(area);
|
|
bencher.iter(|| black_box(line).render(area, &mut buffer));
|
|
});
|
|
}
|
|
group.finish();
|
|
}
|
|
}
|
|
|
|
criterion_group!(benches, line_render);
|
|
criterion_main!(benches);
|