aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorYann E. MORIN <yann.morin.1998@free.fr>2013-07-16 14:39:42 -0400
committerYann E. MORIN <yann.morin.1998@free.fr>2013-07-16 14:39:42 -0400
commit508382a0428f2b2f49da0e0e89c921f07c9306aa (patch)
treed1e929e4a6fe06831c91c5e276c53c1c81486d13 /scripts
parent1407f97aeda5720d6327d69f6058537c0fd469e3 (diff)
kconfig: simplify symbol-search code
There is no need for a double indirection in the temporary array that stores the internediate search results. Reported-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Reviewed-by: Jean Delvare <jdelvare@suse.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kconfig/symbol.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 08d4401e646d..a76b8fd1db4f 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -965,8 +965,8 @@ struct sym_match {
965 */ 965 */
966static int sym_rel_comp(const void *sym1, const void *sym2) 966static int sym_rel_comp(const void *sym1, const void *sym2)
967{ 967{
968 struct sym_match *s1 = *(struct sym_match **)sym1; 968 const struct sym_match *s1 = sym1;
969 struct sym_match *s2 = *(struct sym_match **)sym2; 969 const struct sym_match *s2 = sym2;
970 int exact1, exact2; 970 int exact1, exact2;
971 971
972 /* Exact match: 972 /* Exact match:
@@ -992,7 +992,7 @@ static int sym_rel_comp(const void *sym1, const void *sym2)
992struct symbol **sym_re_search(const char *pattern) 992struct symbol **sym_re_search(const char *pattern)
993{ 993{
994 struct symbol *sym, **sym_arr = NULL; 994 struct symbol *sym, **sym_arr = NULL;
995 struct sym_match **sym_match_arr = NULL; 995 struct sym_match *sym_match_arr = NULL;
996 int i, cnt, size; 996 int i, cnt, size;
997 regex_t re; 997 regex_t re;
998 regmatch_t match[1]; 998 regmatch_t match[1];
@@ -1005,7 +1005,6 @@ struct symbol **sym_re_search(const char *pattern)
1005 return NULL; 1005 return NULL;
1006 1006
1007 for_all_symbols(i, sym) { 1007 for_all_symbols(i, sym) {
1008 struct sym_match *tmp_sym_match;
1009 if (sym->flags & SYMBOL_CONST || !sym->name) 1008 if (sym->flags & SYMBOL_CONST || !sym->name)
1010 continue; 1009 continue;
1011 if (regexec(&re, sym->name, 1, match, 0)) 1010 if (regexec(&re, sym->name, 1, match, 0))
@@ -1013,38 +1012,31 @@ struct symbol **sym_re_search(const char *pattern)
1013 if (cnt >= size) { 1012 if (cnt >= size) {
1014 void *tmp; 1013 void *tmp;
1015 size += 16; 1014 size += 16;
1016 tmp = realloc(sym_match_arr, size * sizeof(struct sym_match *)); 1015 tmp = realloc(sym_match_arr, size * sizeof(struct sym_match));
1017 if (!tmp) 1016 if (!tmp)
1018 goto sym_re_search_free; 1017 goto sym_re_search_free;
1019 sym_match_arr = tmp; 1018 sym_match_arr = tmp;
1020 } 1019 }
1021 sym_calc_value(sym); 1020 sym_calc_value(sym);
1022 tmp_sym_match = (struct sym_match*)malloc(sizeof(struct sym_match));
1023 if (!tmp_sym_match)
1024 goto sym_re_search_free;
1025 tmp_sym_match->sym = sym;
1026 /* As regexec returned 0, we know we have a match, so 1021 /* As regexec returned 0, we know we have a match, so
1027 * we can use match[0].rm_[se]o without further checks 1022 * we can use match[0].rm_[se]o without further checks
1028 */ 1023 */
1029 tmp_sym_match->so = match[0].rm_so; 1024 sym_match_arr[cnt].so = match[0].rm_so;
1030 tmp_sym_match->eo = match[0].rm_eo; 1025 sym_match_arr[cnt].eo = match[0].rm_eo;
1031 sym_match_arr[cnt++] = tmp_sym_match; 1026 sym_match_arr[cnt++].sym = sym;
1032 } 1027 }
1033 if (sym_match_arr) { 1028 if (sym_match_arr) {
1034 qsort(sym_match_arr, cnt, sizeof(struct sym_match*), sym_rel_comp); 1029 qsort(sym_match_arr, cnt, sizeof(struct sym_match), sym_rel_comp);
1035 sym_arr = malloc((cnt+1) * sizeof(struct symbol)); 1030 sym_arr = malloc((cnt+1) * sizeof(struct symbol));
1036 if (!sym_arr) 1031 if (!sym_arr)
1037 goto sym_re_search_free; 1032 goto sym_re_search_free;
1038 for (i = 0; i < cnt; i++) 1033 for (i = 0; i < cnt; i++)
1039 sym_arr[i] = sym_match_arr[i]->sym; 1034 sym_arr[i] = sym_match_arr[i].sym;
1040 sym_arr[cnt] = NULL; 1035 sym_arr[cnt] = NULL;
1041 } 1036 }
1042sym_re_search_free: 1037sym_re_search_free:
1043 if (sym_match_arr) { 1038 /* sym_match_arr can be NULL if no match, but free(NULL) is OK */
1044 for (i = 0; i < cnt; i++) 1039 free(sym_match_arr);
1045 free(sym_match_arr[i]);
1046 free(sym_match_arr);
1047 }
1048 regfree(&re); 1040 regfree(&re);
1049 1041
1050 return sym_arr; 1042 return sym_arr;