comparison src/evalfunc.c @ 9998:3063d1acd0c9 v7.4.2272

commit https://github.com/vim/vim/commit/9f8187c335b4fb07be9095dfdd0fc52670ba3c3f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 27 20:34:01 2016 +0200 patch 7.4.2272 Problem: getbufinfo(), getwininfo() and gettabinfo() are inefficient. Solution: Instead of making a copy of the variables dictionary, use a reference.
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Aug 2016 20:45:05 +0200
parents b9fd9c50be25
children 233289599874
comparison
equal deleted inserted replaced
9997:872a7f55d59a 9998:3063d1acd0c9
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; 3924 dict_T *opts;
3925 dict_T *vars;
3926 tabpage_T *tp; 3925 tabpage_T *tp;
3927 win_T *wp; 3926 win_T *wp;
3928 list_T *windows; 3927 list_T *windows;
3929 3928
3930 dict = dict_alloc(); 3929 dict = dict_alloc();
3941 dict_add_nr_str(dict, "changedtick", buf->b_changedtick, NULL); 3940 dict_add_nr_str(dict, "changedtick", buf->b_changedtick, NULL);
3942 dict_add_nr_str(dict, "hidden", 3941 dict_add_nr_str(dict, "hidden",
3943 buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0, 3942 buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0,
3944 NULL); 3943 NULL);
3945 3944
3946 /* Copy buffer variables */ 3945 /* Get a reference to buffer variables */
3947 vars = dict_copy(buf->b_vars, TRUE, 0); 3946 dict_add_dict(dict, "variables", buf->b_vars);
3948 if (vars != NULL)
3949 dict_add_dict(dict, "variables", vars);
3950 3947
3951 /* Copy buffer options */ 3948 /* Copy buffer options */
3952 opts = get_winbuf_options(TRUE); 3949 opts = get_winbuf_options(TRUE);
3953 if (opts != NULL) 3950 if (opts != NULL)
3954 dict_add_dict(dict, "options", opts); 3951 dict_add_dict(dict, "options", opts);
4992 static dict_T * 4989 static dict_T *
4993 get_tabpage_info(tabpage_T *tp, int tp_idx) 4990 get_tabpage_info(tabpage_T *tp, int tp_idx)
4994 { 4991 {
4995 win_T *wp; 4992 win_T *wp;
4996 dict_T *dict; 4993 dict_T *dict;
4997 dict_T *vars;
4998 list_T *l; 4994 list_T *l;
4999 4995
5000 dict = dict_alloc(); 4996 dict = dict_alloc();
5001 if (dict == NULL) 4997 if (dict == NULL)
5002 return NULL; 4998 return NULL;
5010 wp; wp = wp->w_next) 5006 wp; wp = wp->w_next)
5011 list_append_number(l, (varnumber_T)wp->w_id); 5007 list_append_number(l, (varnumber_T)wp->w_id);
5012 dict_add_list(dict, "windows", l); 5008 dict_add_list(dict, "windows", l);
5013 } 5009 }
5014 5010
5015 /* Copy tabpage variables */ 5011 /* Make a reference to tabpage variables */
5016 vars = dict_copy(tp->tp_vars, TRUE, 0); 5012 dict_add_dict(dict, "variables", tp->tp_vars);
5017 if (vars != NULL)
5018 dict_add_dict(dict, "variables", vars);
5019 5013
5020 return dict; 5014 return dict;
5021 } 5015 }
5022 #endif 5016 #endif
5023 5017
5116 */ 5110 */
5117 static dict_T * 5111 static dict_T *
5118 get_win_info(win_T *wp, short tpnr, short winnr) 5112 get_win_info(win_T *wp, short tpnr, short winnr)
5119 { 5113 {
5120 dict_T *dict; 5114 dict_T *dict;
5121 dict_T *vars;
5122 dict_T *opts; 5115 dict_T *opts;
5123 5116
5124 dict = dict_alloc(); 5117 dict = dict_alloc();
5125 if (dict == NULL) 5118 if (dict == NULL)
5126 return NULL; 5119 return NULL;
5136 dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL); 5129 dict_add_nr_str(dict, "quickfix", bt_quickfix(wp->w_buffer), NULL);
5137 dict_add_nr_str(dict, "loclist", 5130 dict_add_nr_str(dict, "loclist",
5138 (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL); 5131 (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL), NULL);
5139 #endif 5132 #endif
5140 5133
5141 /* Copy window variables */ 5134 /* Make a reference to window variables */
5142 vars = dict_copy(wp->w_vars, TRUE, 0); 5135 dict_add_dict(dict, "variables", wp->w_vars);
5143 if (vars != NULL)
5144 dict_add_dict(dict, "variables", vars);
5145 5136
5146 /* Copy window options */ 5137 /* Copy window options */
5147 opts = get_winbuf_options(FALSE); 5138 opts = get_winbuf_options(FALSE);
5148 if (opts != NULL) 5139 if (opts != NULL)
5149 dict_add_dict(dict, "options", opts); 5140 dict_add_dict(dict, "options", opts);