Skip to content

Commit bacbb67

Browse files
committed
[lib] reorder_line(): Expand LTR-only shortcut condition
* There's almost no extra cost in expanding the shortcut condition to check all the isolating run sequences to be LTR, if there's more than one. This can prevent a bunch of string manipulation when all isolating run sequences are LTR. Benchmark is unchanged: ``` Running target/release/deps/basic-e727a8b30b644dba running 4 tests test bench_1_bidi_info_new_for_ltr_texts ... bench: 1,766 ns/iter (+/- 291) test bench_2_bidi_info_new_for_bidi_texts ... bench: 2,158 ns/iter (+/- 238) test bench_3_reorder_line_for_ltr_texts ... bench: 250 ns/iter (+/- 63) test bench_4_reorder_line_for_bidi_texts ... bench: 594 ns/iter (+/- 72) Running target/release/deps/udhr-c7491ea72b980ef8 running 4 tests test bench_1_bidi_info_new_for_ltr_texts ... bench: 667,871 ns/iter (+/- 114,556) test bench_2_bidi_info_new_for_bidi_texts ... bench: 829,440 ns/iter (+/- 95,813) test bench_3_reorder_line_for_ltr_texts ... bench: 107,855 ns/iter (+/- 12,334) test bench_4_reorder_line_for_bidi_texts ... bench: 367,103 ns/iter (+/- 48,976) ```
1 parent 032f8cc commit bacbb67

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ impl<'text> BidiInfo<'text> {
313313
/// Re-order a line based on resolved levels and return the line in display order.
314314
pub fn reorder_line(&self, para: &ParagraphInfo, line: Range<usize>) -> Cow<'text, str> {
315315
let (levels, runs) = self.visual_runs(para, line.clone());
316-
if runs.len() == 1 && levels[runs[0].start].is_ltr() {
316+
317+
// If all isolating run sequences are LTR, no reordering is needed
318+
if runs.iter().all(|run| levels[run.start].is_ltr()) {
317319
return self.text[line.clone()].into();
318320
}
319321

0 commit comments

Comments
 (0)