mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1865865 - Add fast-path when computing segment's length is 1. r=TYLin
When running wikipedia's page by browsertime benchmark, 0.5%-1% calls of `LineBreaker::ComputeBreakPositions` is that aLength is 1. If this is 1, we only set SOT break in ICU4X's line segmenter. So we can add a fast-path for this situation. `ICU4XLineBreakIterator*` always allocate rust heap, so we can reduce a few heap allocation costs. Differential Revision: https://phabricator.services.mozilla.com/D195523
This commit is contained in:
parent
883a3c8e0b
commit
9f41fa963a
@ -1093,6 +1093,15 @@ void LineBreaker::ComputeBreakPositions(
|
||||
LineBreakRule aLevel, bool aIsChineseOrJapanese, uint8_t* aBreakBefore) {
|
||||
#if defined(MOZ_ICU4X) && defined(JS_HAS_INTL_API)
|
||||
if (StaticPrefs::intl_icu4x_segmenter_enabled()) {
|
||||
if (aLength == 1) {
|
||||
// Although UAX#14 LB2 rule requires never breaking at the start of text
|
||||
// (SOT), ICU4X line segmenter API is designed to match other segmenter in
|
||||
// UAX#29 to always break at the start of text. Hence the optimization
|
||||
// here to avoid calling into ICU4X line segmenter.
|
||||
aBreakBefore[0] = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
memset(aBreakBefore, 0, aLength);
|
||||
|
||||
CheckedInt<int32_t> length = aLength;
|
||||
@ -1253,6 +1262,15 @@ void LineBreaker::ComputeBreakPositions(const uint8_t* aChars, uint32_t aLength,
|
||||
uint8_t* aBreakBefore) {
|
||||
#if defined(MOZ_ICU4X) && defined(JS_HAS_INTL_API)
|
||||
if (StaticPrefs::intl_icu4x_segmenter_enabled()) {
|
||||
if (aLength == 1) {
|
||||
// Although UAX#14 LB2 rule requires never breaking at the start of text
|
||||
// (SOT), ICU4X line segmenter API is designed to match other segmenter in
|
||||
// UAX#29 to always break at the start of text. Hence the optimization
|
||||
// here to avoid calling into ICU4X line segmenter.
|
||||
aBreakBefore[0] = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
memset(aBreakBefore, 0, aLength);
|
||||
|
||||
CheckedInt<int32_t> length = aLength;
|
||||
|
Loading…
Reference in New Issue
Block a user