diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-06-23 13:42:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-23 13:42:57 +0200 |
commit | 05ca14a8810555495c309b8add3002773c77123d (patch) | |
tree | 2325fec350e9942d36d80f45f442cb2ddbf48581 /src | |
parent | 84de4d86553bd47ea8312b2fcc3c2bea9128611c (diff) | |
parent | 9690f8c57b6b918604c662d53cd5ae18c6f9a15d (diff) | |
download | rneovim-05ca14a8810555495c309b8add3002773c77123d.tar.gz rneovim-05ca14a8810555495c309b8add3002773c77123d.tar.bz2 rneovim-05ca14a8810555495c309b8add3002773c77123d.zip |
Merge pull request #19058 from bfredl/miniopt
perf(highlight): use binary search to lookup RGB color names
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/highlight_group.c | 19 | ||||
-rw-r--r-- | src/nvim/main.c | 6 | ||||
-rw-r--r-- | src/nvim/ops.c | 8 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 93d6e65040..ac7f6c4317 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -1751,6 +1751,8 @@ static int syn_add_group(const char *name, size_t len) if (highlight_ga.ga_data == NULL) { highlight_ga.ga_itemsize = sizeof(HlGroup); ga_set_growsize(&highlight_ga, 10); + // 265 builtin groups, will always be used, plus some space + ga_grow(&highlight_ga, 300); } if (highlight_ga.ga_len >= MAX_HL_ID) { @@ -2765,10 +2767,19 @@ RgbValue name_to_color(const char *name, int *idx) return normal_fg; } - for (int i = 0; color_name_table[i].name != NULL; i++) { - if (!STRICMP(name, color_name_table[i].name)) { - *idx = i; - return color_name_table[i].color; + int lo = 0; + int hi = ARRAY_SIZE(color_name_table) - 1; // don't count NULL element + while (lo < hi) { + int m = (lo + hi) / 2; + int cmp = STRICMP(name, color_name_table[m].name); + if (cmp < 0) { + hi = m; + } else if (cmp > 0) { + lo = m + 1; + } else { // found match + *idx = m; + return color_name_table[m].color; + break; } } diff --git a/src/nvim/main.c b/src/nvim/main.c index 71c1ddfae1..2ddbbfbbfb 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -128,6 +128,7 @@ void event_init(void) channel_init(); terminal_init(); ui_init(); + TIME_MSG("event init"); } /// @returns false if main_loop could not be closed gracefully @@ -172,6 +173,8 @@ void early_init(mparm_T *paramp) (int)ovi.dwMajorVersion, (int)ovi.dwMinorVersion); #endif + TIME_MSG("early init"); + #if defined(HAVE_LOCALE_H) // Setup to use the current locale (for ctype() and many other things). // NOTE: Translated messages with encodings other than latin1 will not @@ -184,8 +187,7 @@ void early_init(mparm_T *paramp) if (!win_alloc_first()) { os_exit(0); } - - init_yank(); // init yank buffers + TIME_MSG("init first window"); alist_init(&global_alist); // Init the argument list to empty. global_alist.id = 0; diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 510aa1c8ac..20bbc5b440 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -57,7 +57,7 @@ #include "nvim/vim.h" #include "nvim/window.h" -static yankreg_T y_regs[NUM_REGISTERS]; +static yankreg_T y_regs[NUM_REGISTERS] = { 0 }; static yankreg_T *y_previous = NULL; // ptr to last written yankreg @@ -2571,12 +2571,6 @@ int op_change(oparg_T *oap) return retval; } -/// set all the yank registers to empty (called from main()) -void init_yank(void) -{ - memset(&(y_regs[0]), 0, sizeof(y_regs)); -} - #if defined(EXITFREE) void clear_registers(void) { |