Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-12-31 17:12:31 +0300
committerRuben Bridgewater <ruben@bridgewater.de>2020-01-10 11:11:53 +0300
commit9a1ffa4d7ca5e489179e6ccb2e892086fd23d855 (patch)
treed3c20e0130f3ce92171093cc5e1ec24ec9e53ae1 /src/node_i18n.cc
parentdf1879ac20e0d16286bf3039a49e5fbd31286d1f (diff)
src: improve GetColumnWidth performance
This improves the performance in GetColumnWidth for full width characters. PR-URL: https://github.com/nodejs/node/pull/31112 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_i18n.cc')
-rw-r--r--src/node_i18n.cc19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/node_i18n.cc b/src/node_i18n.cc
index c68e01e1074..7cb7ab35d50 100644
--- a/src/node_i18n.cc
+++ b/src/node_i18n.cc
@@ -728,16 +728,6 @@ static void ToASCII(const FunctionCallbackInfo<Value>& args) {
// Refs: https://github.com/KDE/konsole/blob/8c6a5d13c0/src/konsole_wcwidth.cpp#L101-L223
static int GetColumnWidth(UChar32 codepoint,
bool ambiguous_as_full_width = false) {
- const auto zero_width_mask = U_GC_CC_MASK | // C0/C1 control code
- U_GC_CF_MASK | // Format control character
- U_GC_ME_MASK | // Enclosing mark
- U_GC_MN_MASK; // Nonspacing mark
- if (codepoint != 0x00AD && // SOFT HYPHEN is Cf but not zero-width
- ((U_MASK(u_charType(codepoint)) & zero_width_mask) ||
- u_hasBinaryProperty(codepoint, UCHAR_EMOJI_MODIFIER))) {
- return 0;
- }
-
// UCHAR_EAST_ASIAN_WIDTH is the Unicode property that identifies a
// codepoint as being full width, wide, ambiguous, neutral, narrow,
// or halfwidth.
@@ -761,6 +751,15 @@ static int GetColumnWidth(UChar32 codepoint,
case U_EA_HALFWIDTH:
case U_EA_NARROW:
default:
+ const auto zero_width_mask = U_GC_CC_MASK | // C0/C1 control code
+ U_GC_CF_MASK | // Format control character
+ U_GC_ME_MASK | // Enclosing mark
+ U_GC_MN_MASK; // Nonspacing mark
+ if (codepoint != 0x00AD && // SOFT HYPHEN is Cf but not zero-width
+ ((U_MASK(u_charType(codepoint)) & zero_width_mask) ||
+ u_hasBinaryProperty(codepoint, UCHAR_EMOJI_MODIFIER))) {
+ return 0;
+ }
return 1;
}
}