Skip to content

Commit

Permalink
Bug 1392181 - part2: HasRTLChars() should check if the character is a…
Browse files Browse the repository at this point in the history
…t least equal or larger than the minimum RTL character, U+0590 r=emk

HasRTLChars() appears in profile of attachment 8848015 after landing the patches
for bug 1391538 because the landing made text in <input> or <textarea> always
treated as non-single byte characters.  Therefore, HasRTLChars() is now called
by nsTextFragment::SetTo() a lot in editors.

HasRTLChar() checks if it's in an RTL character for each character until it
becomes true.  However, if character is less than the minimum RTL character,
U+0590, it works faster at least for Western languages.

MozReview-Commit-ID: 4YecxQWUcmK

--HG--
extra : rebase_source : 172be670795f0e2155d4bd5044ee37f652367734
  • Loading branch information
masayuki-nakano committed Aug 21, 2017
1 parent 2eff2ba commit 6b9eda1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions intl/unicharutil/util/nsBidiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsBidiUtils.h"

namespace mozilla {
static const uint32_t kMinRTLChar = 0x0590;
} // namespace mozilla;

#define ARABIC_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_ARABIC_DIGITS)
#define PERSIAN_TO_HINDI_DIGIT_INCREMENT (START_HINDI_DIGITS - START_FARSI_DIGITS)
#define ARABIC_TO_PERSIAN_DIGIT_INCREMENT (START_FARSI_DIGITS - START_ARABIC_DIGITS)
Expand Down Expand Up @@ -90,6 +94,9 @@ bool HasRTLChars(const char16_t* aText, uint32_t aLength)
const char16_t* end = cp + aLength;
while (cp < end) {
uint32_t ch = *cp++;
if (ch < mozilla::kMinRTLChar) {
continue;
}
if (NS_IS_HIGH_SURROGATE(ch) && cp < end && NS_IS_LOW_SURROGATE(*cp)) {
ch = SURROGATE_TO_UCS4(ch, *cp++);
}
Expand Down

0 comments on commit 6b9eda1

Please sign in to comment.