Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a simplified codepath if no bidi isolation controls are present. #131

Merged
merged 4 commits into from
Mar 5, 2024

Conversation

jfkthame
Copy link
Contributor

@jfkthame jfkthame commented Mar 1, 2024

If there aren't any bidi isolation control characters in the paragraph, each level run directly corresponds to one isolating run sequence. (See notes under https://www.unicode.org/reports/tr9/#BD13.) In this case we can take a simplified codepath to process them.

Also, we can avoid the need for a separate pass over the levels array to find level runs by collecting the level runs at the same time as the levels array is being set up, during explicit::compute().

If there aren't any bidi isolation control characters in the paragraph,
each level run directly corresponds to one isolating run sequence.
In this case we can take a simplified codepath to process them.
We can easily accumulate the level runs as part of the initial explicit::compute()
pass over the text; this avoids the need for a separate pass over the levels array
at the beginning of prepare::isolating_run_sequences to collect them.
src/prepare.rs Outdated
@@ -97,7 +101,7 @@ pub fn isolating_run_sequences(
};

isolating_run_sequences.push(IsolatingRunSequence {
runs: vec![run],
runs: vec![run.clone()],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use .drain() or into_iter so we can move instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we can just remove the .clone(), it's not needed here.

@@ -182,6 +190,22 @@ pub fn compute<'a, T: TextSource<'a> + ?Sized>(
levels[i + j] = levels[i];
processing_classes[i + j] = processing_classes[i];
}

// Check if we need to start a new level run.
if i == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're moving level_runs logic here then we should:

  • link to the spec
  • mention in the fn docs that this code also handles that part of the spec
  • ideally, more comments referencing spec list items or other text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added/tidied up comments, as well as added a test for the edge-case of calling the paragraph API with empty text (and RTL direction, which prevents us taking the early exit in compute_bidi_info_for_para).

@Manishearth Manishearth merged commit ca612da into servo:master Mar 5, 2024
7 checks passed
@jfkthame jfkthame deleted the isolates-opt branch March 5, 2024 08:55
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Mar 9, 2024
… changes from servo/unicode-bidi#131. r=platform-i18n-reviewers,supply-chain-reviewers,gregtatum

No change in behavior, just internal performance optimizations.

Differential Revision: https://phabricator.services.mozilla.com/D203729
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this pull request Mar 12, 2024
… changes from servo/unicode-bidi#131. r=platform-i18n-reviewers,supply-chain-reviewers,gregtatum

No change in behavior, just internal performance optimizations.

Differential Revision: https://phabricator.services.mozilla.com/D203729
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants