From 16dda35aeaa98d7cc23345cb87d4379381ee9337 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 27 Feb 2024 10:23:23 +0000 Subject: [PATCH 1/6] Remove redundant imports. --- src/deprecated.rs | 2 -- src/level.rs | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/deprecated.rs b/src/deprecated.rs index 34aae01..c903663 100644 --- a/src/deprecated.rs +++ b/src/deprecated.rs @@ -9,8 +9,6 @@ //! This module holds deprecated assets only. -use alloc::vec::Vec; - use super::*; /// Find the level runs within a line and return them in visual order. diff --git a/src/level.rs b/src/level.rs index 81b327a..5ece025 100644 --- a/src/level.rs +++ b/src/level.rs @@ -17,10 +17,7 @@ use alloc::{ string::{String, ToString}, vec::Vec, }; -use core::{ - convert::{From, Into}, - slice, -}; +use core::slice; use super::char_data::BidiClass; From 899530c022939216c31ac744569e14e2a6a9d988 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 27 Feb 2024 10:25:32 +0000 Subject: [PATCH 2/6] Fix misleading local parameter name in resolve_levels(). --- src/implicit.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/implicit.rs b/src/implicit.rs index 0c6c6d5..fdf81c6 100644 --- a/src/implicit.rs +++ b/src/implicit.rs @@ -567,11 +567,11 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>( /// /// #[cfg_attr(feature = "flame_it", flamer::flame)] -pub fn resolve_levels(original_classes: &[BidiClass], levels: &mut [Level]) -> Level { +pub fn resolve_levels(processing_classes: &[BidiClass], levels: &mut [Level]) -> Level { let mut max_level = Level::ltr(); - assert_eq!(original_classes.len(), levels.len()); + assert_eq!(processing_classes.len(), levels.len()); for i in 0..levels.len() { - match (levels[i].is_rtl(), original_classes[i]) { + match (levels[i].is_rtl(), processing_classes[i]) { (false, AN) | (false, EN) => levels[i].raise(2).expect("Level number error"), (false, R) | (true, L) | (true, EN) | (true, AN) => { levels[i].raise(1).expect("Level number error") From 5a620a6594a1c8942a1fd1183861496bcedb7b7e Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 27 Feb 2024 10:49:56 +0000 Subject: [PATCH 3/6] Use SmallVec for bracket pairs. --- src/implicit.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/implicit.rs b/src/implicit.rs index fdf81c6..c0cfc13 100644 --- a/src/implicit.rs +++ b/src/implicit.rs @@ -9,6 +9,7 @@ //! 3.3.4 - 3.3.6. Resolve implicit levels and types. +#[cfg(not(feature = "smallvec"))] use alloc::vec::Vec; use core::cmp::max; #[cfg(feature = "smallvec")] @@ -250,6 +251,11 @@ pub fn resolve_weak<'a, T: TextSource<'a> + ?Sized>( } } +#[cfg(feature = "smallvec")] +type BracketPairVec = SmallVec::<[BracketPair; 8]>; +#[cfg(not(feature = "smallvec"))] +type BracketPairVec = Vec::; + /// 3.3.5 Resolving Neutral Types /// /// @@ -273,7 +279,8 @@ pub fn resolve_neutral<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>( // > Identify the bracket pairs in the current isolating run sequence according to BD16. // We use processing_classes, not original_classes, due to BD14/BD15 - let bracket_pairs = identify_bracket_pairs(text, data_source, sequence, processing_classes); + let mut bracket_pairs = BracketPairVec::new(); + identify_bracket_pairs(text, data_source, sequence, processing_classes, &mut bracket_pairs); // > For each bracket-pair element in the list of pairs of text positions // @@ -493,8 +500,8 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>( data_source: &D, run_sequence: &IsolatingRunSequence, original_classes: &[BidiClass], -) -> Vec { - let mut ret = vec![]; + bracket_pairs: &mut BracketPairVec, +) { #[cfg(feature = "smallvec")] let mut stack = SmallVec::<[(char, usize, usize); 8]>::new(); #[cfg(not(feature = "smallvec"))] @@ -544,7 +551,7 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>( start_run: element.2, end_run: run_index, }; - ret.push(pair); + bracket_pairs.push(pair); // > Pop the stack through the current stack element inclusively. stack.truncate(stack_index); @@ -557,8 +564,7 @@ fn identify_bracket_pairs<'a, T: TextSource<'a> + ?Sized, D: BidiDataSource>( } // > Sort the list of pairs of text positions in ascending order based on // > the text position of the opening paired bracket. - ret.sort_by_key(|r| r.start); - ret + bracket_pairs.sort_by_key(|r| r.start); } /// 3.3.6 Resolving Implicit Levels From d3df915eea801f12ff8449148c348b1c5098dac5 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 27 Feb 2024 11:03:20 +0000 Subject: [PATCH 4/6] Use SmallVec for the stack in explicit::compute(). --- src/explicit.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/explicit.rs b/src/explicit.rs index d02692e..784ce8d 100644 --- a/src/explicit.rs +++ b/src/explicit.rs @@ -11,6 +11,9 @@ //! //! +#[cfg(feature = "smallvec")] +use smallvec::{SmallVec, smallvec}; + use super::char_data::{ is_rtl, BidiClass::{self, *}, @@ -33,6 +36,12 @@ pub fn compute<'a, T: TextSource<'a> + ?Sized>( assert_eq!(text.len(), original_classes.len()); // + #[cfg(feature = "smallvec")] + let mut stack: SmallVec::<[Status; 8]> = smallvec![Status { + level: para_level, + status: OverrideStatus::Neutral, + }]; + #[cfg(not(feature = "smallvec"))] let mut stack = vec![Status { level: para_level, status: OverrideStatus::Neutral, From ac6370bc527ab0c2f188205bc4a5ac2ef1fb4790 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Tue, 27 Feb 2024 11:13:56 +0000 Subject: [PATCH 5/6] Use SmallVec for local stack in isolating_run_sequences(). --- src/prepare.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/prepare.rs b/src/prepare.rs index e4397b8..0dd3ece 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -14,6 +14,8 @@ use alloc::vec::Vec; use core::cmp::max; use core::ops::Range; +#[cfg(feature = "smallvec")] +use smallvec::{SmallVec, smallvec}; use super::level::Level; use super::BidiClass::{self, *}; @@ -52,6 +54,9 @@ pub fn isolating_run_sequences( // When we encounter an isolate initiator, we push the current sequence onto the // stack so we can resume it after the matching PDI. + #[cfg(feature = "smallvec")] + let mut stack: SmallVec::<[Vec>; 8]> = smallvec![vec![]]; + #[cfg(not(feature = "smallvec"))] let mut stack = vec![vec![]]; for run in runs { From ad433104b179481648914da3e0ccdf7dd599f887 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 29 Feb 2024 13:26:52 +0000 Subject: [PATCH 6/6] cargo fmt --- src/explicit.rs | 4 ++-- src/implicit.rs | 12 +++++++++--- src/prepare.rs | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/explicit.rs b/src/explicit.rs index 784ce8d..3c98bf4 100644 --- a/src/explicit.rs +++ b/src/explicit.rs @@ -12,7 +12,7 @@ //! #[cfg(feature = "smallvec")] -use smallvec::{SmallVec, smallvec}; +use smallvec::{smallvec, SmallVec}; use super::char_data::{ is_rtl, @@ -37,7 +37,7 @@ pub fn compute<'a, T: TextSource<'a> + ?Sized>( // #[cfg(feature = "smallvec")] - let mut stack: SmallVec::<[Status; 8]> = smallvec![Status { + let mut stack: SmallVec<[Status; 8]> = smallvec![Status { level: para_level, status: OverrideStatus::Neutral, }]; diff --git a/src/implicit.rs b/src/implicit.rs index c0cfc13..334afec 100644 --- a/src/implicit.rs +++ b/src/implicit.rs @@ -252,9 +252,9 @@ pub fn resolve_weak<'a, T: TextSource<'a> + ?Sized>( } #[cfg(feature = "smallvec")] -type BracketPairVec = SmallVec::<[BracketPair; 8]>; +type BracketPairVec = SmallVec<[BracketPair; 8]>; #[cfg(not(feature = "smallvec"))] -type BracketPairVec = Vec::; +type BracketPairVec = Vec; /// 3.3.5 Resolving Neutral Types /// @@ -280,7 +280,13 @@ pub fn resolve_neutral<'a, D: BidiDataSource, T: TextSource<'a> + ?Sized>( // > Identify the bracket pairs in the current isolating run sequence according to BD16. // We use processing_classes, not original_classes, due to BD14/BD15 let mut bracket_pairs = BracketPairVec::new(); - identify_bracket_pairs(text, data_source, sequence, processing_classes, &mut bracket_pairs); + identify_bracket_pairs( + text, + data_source, + sequence, + processing_classes, + &mut bracket_pairs, + ); // > For each bracket-pair element in the list of pairs of text positions // diff --git a/src/prepare.rs b/src/prepare.rs index 0dd3ece..f864229 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -15,7 +15,7 @@ use alloc::vec::Vec; use core::cmp::max; use core::ops::Range; #[cfg(feature = "smallvec")] -use smallvec::{SmallVec, smallvec}; +use smallvec::{smallvec, SmallVec}; use super::level::Level; use super::BidiClass::{self, *}; @@ -55,7 +55,7 @@ pub fn isolating_run_sequences( // When we encounter an isolate initiator, we push the current sequence onto the // stack so we can resume it after the matching PDI. #[cfg(feature = "smallvec")] - let mut stack: SmallVec::<[Vec>; 8]> = smallvec![vec![]]; + let mut stack: SmallVec<[Vec>; 8]> = smallvec![vec![]]; #[cfg(not(feature = "smallvec"))] let mut stack = vec![vec![]];