diff src/evalfunc.c @ 10000:233289599874 v7.4.2273

commit https://github.com/vim/vim/commit/3056735ae8a366aa7fcb51872520895251858637 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 27 21:25:44 2016 +0200 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().
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Aug 2016 21:30:06 +0200
parents 3063d1acd0c9
children 84a9ad350a05
line wrap: on
line diff
--- 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 
 	save_curbuf = curbuf;
 	curbuf = buf;
 
-	if (*varname == '&')	/* buffer-local-option */
-	{
-	    if (get_option_tv(&varname, rettv, TRUE) == OK)
+	if (*varname == '&')
+	{
+	    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
 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, shor
 	    (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