From 6fcc2ba9218837db30e4f94db305e8b53e5b1f20 Mon Sep 17 00:00:00 2001 From: Slava Date: Tue, 20 May 2025 13:50:08 +0500 Subject: [PATCH] UNICODE_MODE_VIM: a bit less code, a bit more cpu usage All the loop is reused now, and there is no duplicated code But we have one extra check for each of 4 first digits, that is 4 checks for a character In previous version there was only 1 check for each unicode character. --- quantum/unicode/unicode.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c index a1407099838..f7f84842d03 100644 --- a/quantum/unicode/unicode.c +++ b/quantum/unicode/unicode.c @@ -350,16 +350,6 @@ void register_hex(uint16_t hex) { } void register_hex32(uint32_t hex) { - // In vim, `i_CTRL-V U` waits for exactly 8 digits, so we send them all - // @see `:h i_CTRL-V_digit` - if (unicode_config.input_mode == UNICODE_MODE_VIM) { - for (int i = 7; i >= 0; i--) { - uint8_t digit = ((hex >> (i * 4)) & 0xF); - send_nibble(digit); - } - return; - } - bool first_digit = true; bool needs_leading_zero = (unicode_config.input_mode == UNICODE_MODE_WINCOMPOSE); for (int i = 7; i >= 0; i--) { @@ -372,9 +362,13 @@ void register_hex32(uint32_t hex) { send_nibble_wrapper(0); } - // Always send digits (including zero) if we're down to the last - // two bytes of nibbles. - bool must_send = i < 4; + bool must_send = + // Always send digits (including zero) if we're down to the last + // two bytes of nibbles. + (i < 4) + // In vim, `i_CTRL-V U` waits for exactly 8 digits, so we send them all + // @see `:h i_CTRL-V_digit` + || (unicode_config.input_mode == UNICODE_MODE_VIM); // If we've found a digit worth transmitting, do so. if (digit != 0 || !first_digit || must_send) {