Skip to content

Commit 77fe4b3

Browse files
authored
Only call execute function once per syntax group (#303)
Before the custom `s:hi` function called Vim's `execute` function [1] for each defined attribute which is quite expensive in terms of performance. To improve this the attributes are now concatenate as string and passed to `exec` at the end of the function instead. Co-authored-by: Julien Voisin <jvoisin@google.com> Co-authored-by: Sven Greb <development@svengreb.de> Co-authored-by: Arctic Ice Sudio <development@arcticicestudio.com> [1]: https://vimhelp.org/builtin.txt.html#builtin.txt#execute%28%29 GH-303
1 parent e3eb208 commit 77fe4b3

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

colors/nord.vim

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,27 @@ let g:nord_cursor_line_number_background = get(g:, "nord_cursor_line_number_back
9999
let g:nord_uniform_diff_background = get(g:, "nord_uniform_diff_background", 0)
100100

101101
function! s:hi(group, guifg, guibg, ctermfg, ctermbg, attr, guisp)
102+
let cmd = ""
102103
if a:guifg != ""
103-
exec "hi " . a:group . " guifg=" . a:guifg
104+
let cmd = cmd . " guifg=" . a:guifg
104105
endif
105106
if a:guibg != ""
106-
exec "hi " . a:group . " guibg=" . a:guibg
107+
let cmd = cmd . " guibg=" . a:guibg
107108
endif
108109
if a:ctermfg != ""
109-
exec "hi " . a:group . " ctermfg=" . a:ctermfg
110+
let cmd = cmd . " ctermfg=" . a:ctermfg
110111
endif
111112
if a:ctermbg != ""
112-
exec "hi " . a:group . " ctermbg=" . a:ctermbg
113+
let cmd = cmd . " ctermbg=" . a:ctermbg
113114
endif
114115
if a:attr != ""
115-
exec "hi " . a:group . " gui=" . a:attr . " cterm=" . substitute(a:attr, "undercurl", s:underline, "")
116+
let cmd = cmd . " gui=" . a:attr . " cterm=" . substitute(a:attr, "undercurl", s:underline, "")
116117
endif
117118
if a:guisp != ""
118-
exec "hi " . a:group . " guisp=" . a:guisp
119+
let cmd = cmd . " guisp=" . a:guisp
120+
endif
121+
if cmd != ""
122+
exec "hi " . a:group . cmd
119123
endif
120124
endfunction
121125

@@ -188,12 +192,12 @@ if has('nvim')
188192
call s:hi("DiagnosticUnderlineError" , s:nord11_gui, "", s:nord11_term, "", "undercurl", "")
189193
call s:hi("DiagnosticUnderlineInfo" , s:nord8_gui, "", s:nord8_term, "", "undercurl", "")
190194
call s:hi("DiagnosticUnderlineHint" , s:nord10_gui, "", s:nord10_term, "", "undercurl", "")
191-
195+
192196
"+- Neovim DocumentHighlight -+
193197
call s:hi("LspReferenceText", "", s:nord3_gui, "", s:nord3_term, "", "")
194198
call s:hi("LspReferenceRead", "", s:nord3_gui, "", s:nord3_term, "", "")
195199
call s:hi("LspReferenceWrite", "", s:nord3_gui, "", s:nord3_term, "", "")
196-
200+
197201
"+- Neovim LspSignatureHelp -+
198202
call s:hi("LspSignatureActiveParameter", s:nord8_gui, "", s:nord8_term, "", s:underline, "")
199203
endif
@@ -805,12 +809,12 @@ else
805809
for s:i in range(1,6)
806810
call s:hi("VimwikiHeader".s:i, s:vimwiki_hcolor_guifg[s:i-1] , "", s:vimwiki_hcolor_ctermfg[s:i-1], "", s:bold, "")
807811
endfor
808-
endif
812+
endif
809813
call s:hi("VimwikiLink", s:nord8_gui, "", s:nord8_term, "", s:underline, "")
810814
hi! link VimwikiHeaderChar markdownHeadingDelimiter
811815
hi! link VimwikiHR Keyword
812816
hi! link VimwikiList markdownListMarker
813-
817+
814818
" YAML
815819
" > stephpy/vim-yaml
816820
call s:hi("yamlKey", s:nord7_gui, "", s:nord7_term, "", "", "")

0 commit comments

Comments
 (0)