Mercurial > vim
comparison src/dict.c @ 18777:3a68dc2a1bc1 v8.1.2378
patch 8.1.2378: using old C style comments
Commit: https://github.com/vim/vim/commit/5d18efecfd6c45d69f55268948a22cd0465bb955
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 21:11:22 2019 +0100
patch 8.1.2378: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 21:15:03 +0100 |
parents | 2ec4ed3f5e12 |
children | a3fce2763e83 |
comparison
equal
deleted
inserted
replaced
18776:90a6831d6cd7 | 18777:3a68dc2a1bc1 |
---|---|
13 | 13 |
14 #include "vim.h" | 14 #include "vim.h" |
15 | 15 |
16 #if defined(FEAT_EVAL) || defined(PROTO) | 16 #if defined(FEAT_EVAL) || defined(PROTO) |
17 | 17 |
18 /* List head for garbage collection. Although there can be a reference loop | 18 // List head for garbage collection. Although there can be a reference loop |
19 * from partial to dict to partial, we don't need to keep track of the partial, | 19 // from partial to dict to partial, we don't need to keep track of the partial, |
20 * since it will get freed when the dict is unused and gets freed. */ | 20 // since it will get freed when the dict is unused and gets freed. |
21 static dict_T *first_dict = NULL; /* list of all dicts */ | 21 static dict_T *first_dict = NULL; |
22 | 22 |
23 /* | 23 /* |
24 * Allocate an empty header for a dictionary. | 24 * Allocate an empty header for a dictionary. |
25 */ | 25 */ |
26 dict_T * | 26 dict_T * |
29 dict_T *d; | 29 dict_T *d; |
30 | 30 |
31 d = ALLOC_CLEAR_ONE(dict_T); | 31 d = ALLOC_CLEAR_ONE(dict_T); |
32 if (d != NULL) | 32 if (d != NULL) |
33 { | 33 { |
34 /* Add the dict to the list of dicts for garbage collection. */ | 34 // Add the dict to the list of dicts for garbage collection. |
35 if (first_dict != NULL) | 35 if (first_dict != NULL) |
36 first_dict->dv_used_prev = d; | 36 first_dict->dv_used_prev = d; |
37 d->dv_used_next = first_dict; | 37 d->dv_used_next = first_dict; |
38 d->dv_used_prev = NULL; | 38 d->dv_used_prev = NULL; |
39 first_dict = d; | 39 first_dict = d; |
107 { | 107 { |
108 int todo; | 108 int todo; |
109 hashitem_T *hi; | 109 hashitem_T *hi; |
110 dictitem_T *di; | 110 dictitem_T *di; |
111 | 111 |
112 /* Lock the hashtab, we don't want it to resize while freeing items. */ | 112 // Lock the hashtab, we don't want it to resize while freeing items. |
113 hash_lock(&d->dv_hashtab); | 113 hash_lock(&d->dv_hashtab); |
114 todo = (int)d->dv_hashtab.ht_used; | 114 todo = (int)d->dv_hashtab.ht_used; |
115 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) | 115 for (hi = d->dv_hashtab.ht_array; todo > 0; ++hi) |
116 { | 116 { |
117 if (!HASHITEM_EMPTY(hi)) | 117 if (!HASHITEM_EMPTY(hi)) |
118 { | 118 { |
119 /* Remove the item before deleting it, just in case there is | 119 // Remove the item before deleting it, just in case there is |
120 * something recursive causing trouble. */ | 120 // something recursive causing trouble. |
121 di = HI2DI(hi); | 121 di = HI2DI(hi); |
122 hash_remove(&d->dv_hashtab, hi); | 122 hash_remove(&d->dv_hashtab, hi); |
123 dictitem_free(di); | 123 dictitem_free(di); |
124 --todo; | 124 --todo; |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 /* The hashtab is still locked, it has to be re-initialized anyway */ | 128 // The hashtab is still locked, it has to be re-initialized anyway |
129 hash_clear(&d->dv_hashtab); | 129 hash_clear(&d->dv_hashtab); |
130 } | 130 } |
131 | 131 |
132 static void | 132 static void |
133 dict_free_dict(dict_T *d) | 133 dict_free_dict(dict_T *d) |
134 { | 134 { |
135 /* Remove the dict from the list of dicts for garbage collection. */ | 135 // Remove the dict from the list of dicts for garbage collection. |
136 if (d->dv_used_prev == NULL) | 136 if (d->dv_used_prev == NULL) |
137 first_dict = d->dv_used_next; | 137 first_dict = d->dv_used_next; |
138 else | 138 else |
139 d->dv_used_prev->dv_used_next = d->dv_used_next; | 139 d->dv_used_prev->dv_used_next = d->dv_used_next; |
140 if (d->dv_used_next != NULL) | 140 if (d->dv_used_next != NULL) |
174 int did_free = FALSE; | 174 int did_free = FALSE; |
175 | 175 |
176 for (dd = first_dict; dd != NULL; dd = dd->dv_used_next) | 176 for (dd = first_dict; dd != NULL; dd = dd->dv_used_next) |
177 if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) | 177 if ((dd->dv_copyID & COPYID_MASK) != (copyID & COPYID_MASK)) |
178 { | 178 { |
179 /* Free the Dictionary and ordinary items it contains, but don't | 179 // Free the Dictionary and ordinary items it contains, but don't |
180 * recurse into Lists and Dictionaries, they will be in the list | 180 // recurse into Lists and Dictionaries, they will be in the list |
181 * of dicts or list of lists. */ | 181 // of dicts or list of lists. |
182 dict_free_contents(dd); | 182 dict_free_contents(dd); |
183 did_free = TRUE; | 183 did_free = TRUE; |
184 } | 184 } |
185 return did_free; | 185 return did_free; |
186 } | 186 } |
575 if (akey == NULL) | 575 if (akey == NULL) |
576 return NULL; | 576 return NULL; |
577 } | 577 } |
578 else | 578 else |
579 { | 579 { |
580 /* Avoid a malloc/free by using buf[]. */ | 580 // Avoid a malloc/free by using buf[]. |
581 vim_strncpy(buf, key, len); | 581 vim_strncpy(buf, key, len); |
582 akey = buf; | 582 akey = buf; |
583 } | 583 } |
584 | 584 |
585 hi = hash_find(&d->dv_hashtab, akey); | 585 hi = hash_find(&d->dv_hashtab, akey); |
762 * first item. | 762 * first item. |
763 * But {} is an empty Dictionary. | 763 * But {} is an empty Dictionary. |
764 */ | 764 */ |
765 if (*start != '}') | 765 if (*start != '}') |
766 { | 766 { |
767 if (eval1(&start, &tv, FALSE) == FAIL) /* recursive! */ | 767 if (eval1(&start, &tv, FALSE) == FAIL) // recursive! |
768 return FAIL; | 768 return FAIL; |
769 if (*start == '}') | 769 if (*start == '}') |
770 return NOTDONE; | 770 return NOTDONE; |
771 } | 771 } |
772 | 772 |
796 if (evaluate) | 796 if (evaluate) |
797 { | 797 { |
798 key = tv_get_string_buf_chk(&tvkey, buf); | 798 key = tv_get_string_buf_chk(&tvkey, buf); |
799 if (key == NULL) | 799 if (key == NULL) |
800 { | 800 { |
801 /* "key" is NULL when tv_get_string_buf_chk() gave an errmsg */ | 801 // "key" is NULL when tv_get_string_buf_chk() gave an errmsg |
802 clear_tv(&tvkey); | 802 clear_tv(&tvkey); |
803 goto failret; | 803 goto failret; |
804 } | 804 } |
805 } | 805 } |
806 | 806 |
807 *arg = skipwhite(*arg + 1); | 807 *arg = skipwhite(*arg + 1); |
808 if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ | 808 if (eval1(arg, &tv, evaluate) == FAIL) // recursive! |
809 { | 809 { |
810 if (evaluate) | 810 if (evaluate) |
811 clear_tv(&tvkey); | 811 clear_tv(&tvkey); |
812 goto failret; | 812 goto failret; |
813 } | 813 } |
879 { | 879 { |
880 --todo; | 880 --todo; |
881 di1 = dict_find(d1, hi2->hi_key, -1); | 881 di1 = dict_find(d1, hi2->hi_key, -1); |
882 if (d1->dv_scope != 0) | 882 if (d1->dv_scope != 0) |
883 { | 883 { |
884 /* Disallow replacing a builtin function in l: and g:. | 884 // Disallow replacing a builtin function in l: and g:. |
885 * Check the key to be valid when adding to any scope. */ | 885 // Check the key to be valid when adding to any scope. |
886 if (d1->dv_scope == VAR_DEF_SCOPE | 886 if (d1->dv_scope == VAR_DEF_SCOPE |
887 && HI2DI(hi2)->di_tv.v_type == VAR_FUNC | 887 && HI2DI(hi2)->di_tv.v_type == VAR_FUNC |
888 && var_check_func_name(hi2->hi_key, di1 == NULL)) | 888 && var_check_func_name(hi2->hi_key, di1 == NULL)) |
889 break; | 889 break; |
890 if (!valid_varname(hi2->hi_key)) | 890 if (!valid_varname(hi2->hi_key)) |
927 */ | 927 */ |
928 int | 928 int |
929 dict_equal( | 929 dict_equal( |
930 dict_T *d1, | 930 dict_T *d1, |
931 dict_T *d2, | 931 dict_T *d2, |
932 int ic, /* ignore case for strings */ | 932 int ic, // ignore case for strings |
933 int recursive) /* TRUE when used recursively */ | 933 int recursive) // TRUE when used recursively |
934 { | 934 { |
935 hashitem_T *hi; | 935 hashitem_T *hi; |
936 dictitem_T *item2; | 936 dictitem_T *item2; |
937 int todo; | 937 int todo; |
938 | 938 |
1002 break; | 1002 break; |
1003 list_append(rettv->vval.v_list, li); | 1003 list_append(rettv->vval.v_list, li); |
1004 | 1004 |
1005 if (what == 0) | 1005 if (what == 0) |
1006 { | 1006 { |
1007 /* keys() */ | 1007 // keys() |
1008 li->li_tv.v_type = VAR_STRING; | 1008 li->li_tv.v_type = VAR_STRING; |
1009 li->li_tv.v_lock = 0; | 1009 li->li_tv.v_lock = 0; |
1010 li->li_tv.vval.v_string = vim_strsave(di->di_key); | 1010 li->li_tv.vval.v_string = vim_strsave(di->di_key); |
1011 } | 1011 } |
1012 else if (what == 1) | 1012 else if (what == 1) |
1013 { | 1013 { |
1014 /* values() */ | 1014 // values() |
1015 copy_tv(&di->di_tv, &li->li_tv); | 1015 copy_tv(&di->di_tv, &li->li_tv); |
1016 } | 1016 } |
1017 else | 1017 else |
1018 { | 1018 { |
1019 /* items() */ | 1019 // items() |
1020 l2 = list_alloc(); | 1020 l2 = list_alloc(); |
1021 li->li_tv.v_type = VAR_LIST; | 1021 li->li_tv.v_type = VAR_LIST; |
1022 li->li_tv.v_lock = 0; | 1022 li->li_tv.v_lock = 0; |
1023 li->li_tv.vval.v_list = l2; | 1023 li->li_tv.vval.v_list = l2; |
1024 if (l2 == NULL) | 1024 if (l2 == NULL) |
1077 dict_set_items_ro(dict_T *di) | 1077 dict_set_items_ro(dict_T *di) |
1078 { | 1078 { |
1079 int todo = (int)di->dv_hashtab.ht_used; | 1079 int todo = (int)di->dv_hashtab.ht_used; |
1080 hashitem_T *hi; | 1080 hashitem_T *hi; |
1081 | 1081 |
1082 /* Set readonly */ | 1082 // Set readonly |
1083 for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi) | 1083 for (hi = di->dv_hashtab.ht_array; todo > 0 ; ++hi) |
1084 { | 1084 { |
1085 if (HASHITEM_EMPTY(hi)) | 1085 if (HASHITEM_EMPTY(hi)) |
1086 continue; | 1086 continue; |
1087 --todo; | 1087 --todo; |
1137 } | 1137 } |
1138 } | 1138 } |
1139 } | 1139 } |
1140 } | 1140 } |
1141 | 1141 |
1142 #endif /* defined(FEAT_EVAL) */ | 1142 #endif // defined(FEAT_EVAL) |