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.
This commit is contained in:
Slava 2025-05-20 13:50:08 +05:00
parent fc09ffb34a
commit 6fcc2ba921

View File

@ -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) {