From f40c054a6a0f1b4c0cb13b686ac49a1bcb4c2151 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 21 Jan 2022 17:10:52 +0100 Subject: [PATCH] Replace hangul hack with widecharwidth version This updates widecharwidth to 6d3d55b419db93934517cb568d1a3d95909b4c7b, which includes the same Hangul Jamo check in a separate table. This should slightly speed up most width calculation because we no longer need to do it for most chars, including the overwhelmingly common ascii ones. Also the range is increased and should better match reality. --- src/fallback.cpp | 6 ------ src/widecharwidth/widechar_width.h | 10 +++++++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/fallback.cpp b/src/fallback.cpp index c93d685be..d5104daab 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -243,12 +243,6 @@ int fish_wcwidth(wchar_t wc) { else if (wc == variation_selector_15) return 0; - // Korean Hangul Jamo median vowels and final consonants. - // These can either appear in combined form, taking 0 width themselves, - // or standalone with a 1 width. Since that's literally not expressible with wcwidth(), - // we take the position that the typical way for them to show up is composed. - if (wc >= L'\u1160' && wc <= L'\u11FF') return 0; - // Check for Emoji_Modifier property. Only the Fitzpatrick modifiers have this, in range // 1F3FB..1F3FF. This is a hack because such an emoji appearing on its own would be drawn as // width 2, but that's unlikely to be useful. See #8275. diff --git a/src/widecharwidth/widechar_width.h b/src/widecharwidth/widechar_width.h index 0843f7b6c..cc849745a 100644 --- a/src/widecharwidth/widechar_width.h +++ b/src/widecharwidth/widechar_width.h @@ -1,5 +1,5 @@ /** - * widechar_width.h, generated on 2021-10-26. + * widechar_width.h, generated on 2022-01-01. * See https://github.com/ridiculousfish/widecharwidth/ * * SHA1 file hashes: @@ -378,6 +378,12 @@ static const struct widechar_range widechar_combining_table[] = { {0xE0100, 0xE01EF} }; +/* Width 0 combining letters. */ +static const struct widechar_range widechar_combiningletters_table[] = { + {0x01160, 0x011FF}, + {0x0D7B0, 0x0D7FF} +}; + /* Width 2 characters. */ static const struct widechar_range widechar_doublewide_table[] = { {0x01100, 0x0115F}, @@ -1463,6 +1469,8 @@ int widechar_wcwidth(uint32_t c) { return widechar_non_character; if (widechar_in_table(widechar_combining_table, c)) return widechar_combining; + if (widechar_in_table(widechar_combiningletters_table, c)) + return widechar_combining; if (widechar_in_table(widechar_doublewide_table, c)) return 2; if (widechar_in_table(widechar_ambiguous_table, c))