diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-08-27 21:25:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-08-27 21:25:44 +0200 |
commit | 3056735ae8a366aa7fcb51872520895251858637 (patch) | |
tree | 329de3dbeea7c06972c0ea41929b636f9ef47540 /src | |
parent | 9f8187c335b4fb07be9095dfdd0fc52670ba3c3f (diff) |
patch 7.4.2273v7.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().
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 18 | ||||
-rw-r--r-- | src/evalfunc.c | 32 | ||||
-rw-r--r-- | src/testdir/test_bufwintabinfo.vim | 26 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 57 insertions, 21 deletions
diff --git a/src/eval.c b/src/eval.c index 350173a234..a8835b10be 100644 --- a/src/eval.c +++ b/src/eval.c @@ -8470,9 +8470,23 @@ getwinvar( || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) #endif { - if (*varname == '&') /* window-local-option */ + if (*varname == '&') { - if (get_option_tv(&varname, rettv, 1) == OK) + 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 diff --git a/src/evalfunc.c b/src/evalfunc.c index 1a2ea8621c..7ccf524e61 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -3921,7 +3921,6 @@ get_buffer_signs(buf_T *buf, list_T *l) get_buffer_info(buf_T *buf) { dict_T *dict; - dict_T *opts; tabpage_T *tp; win_T *wp; list_T *windows; @@ -3945,11 +3944,6 @@ get_buffer_info(buf_T *buf) /* Get a reference to buffer variables */ dict_add_dict(dict, "variables", buf->b_vars); - /* Copy buffer options */ - opts = get_winbuf_options(TRUE); - if (opts != NULL) - dict_add_dict(dict, "options", opts); - /* List of windows displaying this buffer */ windows = list_alloc(); if (windows != NULL) @@ -4156,9 +4150,23 @@ f_getbufvar(typval_T *argvars, typval_T *rettv) save_curbuf = curbuf; curbuf = buf; - if (*varname == '&') /* buffer-local-option */ + if (*varname == '&') { - 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) @@ -5112,7 +5120,6 @@ f_gettabwinvar(typval_T *argvars, typval_T *rettv) get_win_info(win_T *wp, short tpnr, short winnr) { dict_T *dict; - dict_T *opts; dict = dict_alloc(); if (dict == NULL) @@ -5131,14 +5138,9 @@ get_win_info(win_T *wp, short tpnr, short winnr) (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL); #endif - /* Make a reference to window variables */ + /* Add a reference to window variables */ dict_add_dict(dict, "variables", wp->w_vars); - /* Copy window options */ - opts = get_winbuf_options(FALSE); - if (opts != NULL) - dict_add_dict(dict, "options", opts); - return dict; } #endif diff --git a/src/testdir/test_bufwintabinfo.vim b/src/testdir/test_bufwintabinfo.vim index 1c88cf53af..5c916e2dd7 100644 --- a/src/testdir/test_bufwintabinfo.vim +++ b/src/testdir/test_bufwintabinfo.vim @@ -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,9 +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) - if has('signs') - call assert_equal('auto', winlist[0].options.signcolumn) - endif call assert_equal(2, winlist[3].tabnr) call assert_equal('green', winlist[2].variables.signal) call assert_equal(winwidth(1), winlist[0].width) @@ -83,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 diff --git a/src/version.c b/src/version.c index 8f435dba39..4a190972a5 100644 --- a/src/version.c +++ b/src/version.c @@ -764,6 +764,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2273, +/**/ 2272, /**/ 2271, |