diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-02-06 20:47:59 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-02-06 20:47:59 +1100 |
| commit | 707904a91ba77f27fc812121fc353371edd19d76 (patch) | |
| tree | 98ea00baaecfc91e2194c62ef9ce7b250b618272 /src | |
| parent | c97add7f5a181f459b2f349069507093be2bc738 (diff) | |
Avoid calling iswalnum for ascii characters
iswalnum can be pretty expensive as its a shared library call.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unicode.hh | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/unicode.hh b/src/unicode.hh index a385b6eb..fd35ecf0 100644 --- a/src/unicode.hh +++ b/src/unicode.hh @@ -60,12 +60,23 @@ inline bool is_blank(Codepoint c) noexcept is_horizontal_blank(c) ; } +inline bool is_basic_alpha(Codepoint c) noexcept +{ + return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z'); +} + +inline bool is_basic_digit(Codepoint c) noexcept +{ + return c >= '0' and c <= '9'; +} + enum WordType { Word, WORD }; template<WordType word_type = Word> inline bool is_word(Codepoint c, ConstArrayView<Codepoint> extra_word_chars = {'_'}) noexcept { - return iswalnum((wchar_t)c) or contains(extra_word_chars, c); + return (c < 128 ? is_basic_alpha(c) or is_basic_digit(c) : iswalnum((wchar_t)c)) or + contains(extra_word_chars, c); } template<> @@ -79,16 +90,6 @@ inline bool is_punctuation(Codepoint c, ConstArrayView<Codepoint> extra_word_cha return not (is_word(c, extra_word_chars) or is_blank(c)); } -inline bool is_basic_alpha(Codepoint c) noexcept -{ - return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z'); -} - -inline bool is_basic_digit(Codepoint c) noexcept -{ - return c >= '0' and c <= '9'; -} - inline bool is_identifier(Codepoint c) noexcept { return is_basic_alpha(c) or is_basic_digit(c) or |
