mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 00:46:30 +00:00
vim-patch:7.4.2273
Problem: getwininfo() and getbufinfo() are inefficient.
Solution: Do not make a copy of all window/buffer-local options. Make it
possible to get them with gettabwinvar() or getbufvar().
3056735ae8
This commit is contained in:
@@ -9883,12 +9883,6 @@ static dict_T *get_buffer_info(buf_T *buf)
|
||||
// Get a reference to buffer variables
|
||||
dict_add_dict(dict, "variables", buf->b_vars);
|
||||
|
||||
// Copy buffer options
|
||||
dict_T *opts = get_winbuf_options(true);
|
||||
if (opts != NULL) {
|
||||
dict_add_dict(dict, "options", opts);
|
||||
}
|
||||
|
||||
// List of windows displaying this buffer
|
||||
list_T *windows = list_alloc();
|
||||
FOR_ALL_TAB_WINDOWS(tp, wp) {
|
||||
@@ -10056,8 +10050,20 @@ static void f_getbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
curbuf = buf;
|
||||
|
||||
if (*varname == '&') { /* buffer-local-option */
|
||||
if (get_option_tv(&varname, rettv, TRUE) == OK)
|
||||
if (varname[1] == NUL) {
|
||||
// get all buffer-local options in a dict
|
||||
dict_T *opts = get_winbuf_options(true);
|
||||
|
||||
if (opts != NULL) {
|
||||
rettv->v_type = VAR_DICT;
|
||||
rettv->vval.v_dict = opts;
|
||||
opts->dv_refcount++;
|
||||
done = true;
|
||||
}
|
||||
} else if (get_option_tv(&varname, rettv, true) == OK) {
|
||||
// buffer-local-option
|
||||
done = TRUE;
|
||||
}
|
||||
} else if (STRCMP(varname, "changedtick") == 0) {
|
||||
rettv->v_type = VAR_NUMBER;
|
||||
rettv->vval.v_number = curbuf->b_changedtick;
|
||||
@@ -10904,15 +10910,9 @@ static dict_T *get_win_info(win_T *wp, short tpnr, short winnr)
|
||||
(bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL),
|
||||
NULL);
|
||||
|
||||
// Make a reference to window variables
|
||||
// Add a reference to window variables
|
||||
dict_add_dict(dict, "variables", wp->w_vars);
|
||||
|
||||
// Copy window options
|
||||
dict_T *opts = get_winbuf_options(false);
|
||||
if (opts != NULL) {
|
||||
dict_add_dict(dict, "options", opts);
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
@@ -11072,8 +11072,19 @@ getwinvar (
|
||||
bool need_switch_win = tp != curtab || win != curwin;
|
||||
if (!need_switch_win
|
||||
|| switch_win(&oldcurwin, &oldtabpage, win, tp, true) == OK) {
|
||||
if (*varname == '&') { // window-local-option
|
||||
if (get_option_tv(&varname, rettv, 1) == OK) {
|
||||
if (*varname == '&') {
|
||||
if (varname[1] == NUL) {
|
||||
// get all window-local options in a dict
|
||||
dict_T *opts = get_winbuf_options(false);
|
||||
|
||||
if (opts != NULL) {
|
||||
rettv->v_type = VAR_DICT;
|
||||
rettv->vval.v_dict = opts;
|
||||
opts->dv_refcount++;
|
||||
done = true;
|
||||
}
|
||||
} else if (get_option_tv(&varname, rettv, 1) == OK) {
|
||||
// window-local-option
|
||||
done = true;
|
||||
}
|
||||
} else {
|
||||
|
@@ -18,7 +18,6 @@ function Test_getbufwintabinfo()
|
||||
let b:editor = 'vim'
|
||||
let l = getbufinfo('%')
|
||||
call assert_equal(bufnr('%'), l[0].bufnr)
|
||||
call assert_equal(8, l[0].options.tabstop)
|
||||
call assert_equal('vim', l[0].variables.editor)
|
||||
call assert_notequal(-1, index(l[0].windows, bufwinid('%')))
|
||||
|
||||
@@ -49,7 +48,6 @@ function Test_getbufwintabinfo()
|
||||
call assert_equal(winbufnr(2), winlist[1].bufnr)
|
||||
call assert_equal(winheight(2), winlist[1].height)
|
||||
call assert_equal(1, winlist[2].winnr)
|
||||
call assert_equal('auto', winlist[0].options.signcolumn)
|
||||
call assert_equal(2, winlist[3].tabnr)
|
||||
call assert_equal('green', winlist[2].variables.signal)
|
||||
call assert_equal(winwidth(1), winlist[0].width)
|
||||
@@ -81,3 +79,25 @@ function Test_getbufwintabinfo()
|
||||
call assert_false(winlist[2].loclist)
|
||||
wincmd t | only
|
||||
endfunction
|
||||
|
||||
function Test_get_buf_options()
|
||||
let opts = getbufvar(bufnr('%'), '&')
|
||||
call assert_equal(v:t_dict, type(opts))
|
||||
call assert_equal(8, opts.tabstop)
|
||||
endfunc
|
||||
|
||||
function Test_get_win_options()
|
||||
let opts = getwinvar(1, '&')
|
||||
call assert_equal(v:t_dict, type(opts))
|
||||
call assert_equal(0, opts.linebreak)
|
||||
if has('signs')
|
||||
call assert_equal('auto', opts.signcolumn)
|
||||
endif
|
||||
|
||||
let opts = gettabwinvar(1, 1, '&')
|
||||
call assert_equal(v:t_dict, type(opts))
|
||||
call assert_equal(0, opts.linebreak)
|
||||
if has('signs')
|
||||
call assert_equal('auto', opts.signcolumn)
|
||||
endif
|
||||
endfunc
|
||||
|
@@ -167,7 +167,7 @@ static int included_patches[] = {
|
||||
// 2276,
|
||||
// 2275,
|
||||
2274,
|
||||
// 2273,
|
||||
2273,
|
||||
2272,
|
||||
// 2271 NA
|
||||
// 2270 NA
|
||||
|
Reference in New Issue
Block a user