Skip to content

Commit d2a10ad

Browse files
BridgeARMylesBorins
authored andcommitted
src: improve GetColumnWidth performance
This improves the performance in GetColumnWidth for full width characters. PR-URL: #31112 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f0506c3 commit d2a10ad

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/node_i18n.cc

+9-10
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,6 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
728728
// Refs: https://github.com./KDE/konsole/blob/8c6a5d13c0/src/konsole_wcwidth.cpp#L101-L223
729729
static int GetColumnWidth(UChar32 codepoint,
730730
bool ambiguous_as_full_width = false) {
731-
const auto zero_width_mask = U_GC_CC_MASK | // C0/C1 control code
732-
U_GC_CF_MASK | // Format control character
733-
U_GC_ME_MASK | // Enclosing mark
734-
U_GC_MN_MASK; // Nonspacing mark
735-
if (codepoint != 0x00AD && // SOFT HYPHEN is Cf but not zero-width
736-
((U_MASK(u_charType(codepoint)) & zero_width_mask) ||
737-
u_hasBinaryProperty(codepoint, UCHAR_EMOJI_MODIFIER))) {
738-
return 0;
739-
}
740-
741731
// UCHAR_EAST_ASIAN_WIDTH is the Unicode property that identifies a
742732
// codepoint as being full width, wide, ambiguous, neutral, narrow,
743733
// or halfwidth.
@@ -761,6 +751,15 @@ static int GetColumnWidth(UChar32 codepoint,
761751
case U_EA_HALFWIDTH:
762752
case U_EA_NARROW:
763753
default:
754+
const auto zero_width_mask = U_GC_CC_MASK | // C0/C1 control code
755+
U_GC_CF_MASK | // Format control character
756+
U_GC_ME_MASK | // Enclosing mark
757+
U_GC_MN_MASK; // Nonspacing mark
758+
if (codepoint != 0x00AD && // SOFT HYPHEN is Cf but not zero-width
759+
((U_MASK(u_charType(codepoint)) & zero_width_mask) ||
760+
u_hasBinaryProperty(codepoint, UCHAR_EMOJI_MODIFIER))) {
761+
return 0;
762+
}
764763
return 1;
765764
}
766765
}

0 commit comments

Comments
 (0)