comparison 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
comparison
equal deleted inserted replaced
9999:2c5b2fc3a9f9 10000:233289599874
3919 */ 3919 */
3920 static dict_T * 3920 static dict_T *
3921 get_buffer_info(buf_T *buf) 3921 get_buffer_info(buf_T *buf)
3922 { 3922 {
3923 dict_T *dict; 3923 dict_T *dict;
3924 dict_T *opts;
3925 tabpage_T *tp; 3924 tabpage_T *tp;
3926 win_T *wp; 3925 win_T *wp;
3927 list_T *windows; 3926 list_T *windows;
3928 3927
3929 dict = dict_alloc(); 3928 dict = dict_alloc();
3943 NULL); 3942 NULL);
3944 3943
3945 /* Get a reference to buffer variables */ 3944 /* Get a reference to buffer variables */
3946 dict_add_dict(dict, "variables", buf->b_vars); 3945 dict_add_dict(dict, "variables", buf->b_vars);
3947 3946
3948 /* Copy buffer options */
3949 opts = get_winbuf_options(TRUE);
3950 if (opts != NULL)
3951 dict_add_dict(dict, "options", opts);
3952
3953 /* List of windows displaying this buffer */ 3947 /* List of windows displaying this buffer */
3954 windows = list_alloc(); 3948 windows = list_alloc();
3955 if (windows != NULL) 3949 if (windows != NULL)
3956 { 3950 {
3957 FOR_ALL_TAB_WINDOWS(tp, wp) 3951 FOR_ALL_TAB_WINDOWS(tp, wp)
4154 { 4148 {
4155 /* set curbuf to be our buf, temporarily */ 4149 /* set curbuf to be our buf, temporarily */
4156 save_curbuf = curbuf; 4150 save_curbuf = curbuf;
4157 curbuf = buf; 4151 curbuf = buf;
4158 4152
4159 if (*varname == '&') /* buffer-local-option */ 4153 if (*varname == '&')
4160 { 4154 {
4161 if (get_option_tv(&varname, rettv, TRUE) == OK) 4155 if (varname[1] == NUL)
4156 {
4157 /* get all buffer-local options in a dict */
4158 dict_T *opts = get_winbuf_options(TRUE);
4159
4160 if (opts != NULL)
4161 {
4162 rettv->v_type = VAR_DICT;
4163 rettv->vval.v_dict = opts;
4164 ++opts->dv_refcount;
4165 done = TRUE;
4166 }
4167 }
4168 else if (get_option_tv(&varname, rettv, TRUE) == OK)
4169 /* buffer-local-option */
4162 done = TRUE; 4170 done = TRUE;
4163 } 4171 }
4164 else if (STRCMP(varname, "changedtick") == 0) 4172 else if (STRCMP(varname, "changedtick") == 0)
4165 { 4173 {
4166 rettv->v_type = VAR_NUMBER; 4174 rettv->v_type = VAR_NUMBER;
5110 */ 5118 */
5111 static dict_T * 5119 static dict_T *
5112 get_win_info(win_T *wp, short tpnr, short winnr) 5120 get_win_info(win_T *wp, short tpnr, short winnr)
5113 { 5121 {
5114 dict_T *dict; 5122 dict_T *dict;
5115 dict_T *opts;
5116 5123
5117 dict = dict_alloc(); 5124 dict = dict_alloc();
5118 if (dict == NULL) 5125 if (dict == NULL)
5119 return NULL; 5126 return NULL;
5120 5127
5129 dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL); 5136 dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL);
5130 dict_add_nr_str(dict, "loclist", 5137 dict_add_nr_str(dict, "loclist",
5131 (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL); 5138 (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL);
5132 #endif 5139 #endif
5133 5140
5134 /* Make a reference to window variables */ 5141 /* Add a reference to window variables */
5135 dict_add_dict(dict, "variables", wp->w_vars); 5142 dict_add_dict(dict, "variables", wp->w_vars);
5136
5137 /* Copy window options */
5138 opts = get_winbuf_options(FALSE);
5139 if (opts != NULL)
5140 dict_add_dict(dict, "options", opts);
5141 5143
5142 return dict; 5144 return dict;
5143 } 5145 }
5144 #endif 5146 #endif
5145 5147