Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kconfig: gconf: inline fill_row() into set_node()

The row[] array is used to prepare data passed to set_node(), but this
indirection is unnecessary. Squash fill_row() into set_node() and call
gtk_tree_store_set() directly.

Also, calling gdk_pixbuf_new_from_xpm_data() for every row is
inefficient. Call it once and store the resulting pixbuf in a global
variable.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+106 -166
+106 -166
scripts/kconfig/gconf.c
··· 44 44 static GtkTextTag *tag1, *tag2; 45 45 46 46 static GtkTreeStore *tree1, *tree2; 47 + static GdkPixbuf *pix_menu; 47 48 48 49 static struct menu *browsed; // browsed menu for SINGLE/SPLIT view 49 50 static struct menu *selected; // selected entry ··· 59 58 static void display_list(void); 60 59 static void display_tree(GtkTreeStore *store, struct menu *menu); 61 60 static void display_tree_part(void); 62 - static gchar **fill_row(struct menu *menu); 63 - static void set_node(GtkTreeStore *tree, GtkTreeIter *node, 64 - struct menu *menu, gchar **row); 65 61 66 62 static void conf_changed(bool dirty) 67 63 { ··· 171 173 _update_row_visibility(GTK_TREE_VIEW(tree2_w)); 172 174 } 173 175 176 + static void set_node(GtkTreeStore *tree, GtkTreeIter *node, struct menu *menu) 177 + { 178 + struct symbol *sym = menu->sym; 179 + tristate val; 180 + gchar *option; 181 + const gchar *_no = ""; 182 + const gchar *_mod = ""; 183 + const gchar *_yes = ""; 184 + const gchar *value = ""; 185 + GdkColor color; 186 + gboolean editable = FALSE; 187 + gboolean btnvis = FALSE; 188 + 189 + option = g_strdup_printf("%s %s %s %s", 190 + menu->type == M_COMMENT ? "***" : "", 191 + menu_get_prompt(menu), 192 + menu->type == M_COMMENT ? "***" : "", 193 + sym && !sym_has_value(sym) ? "(NEW)" : ""); 194 + 195 + gdk_color_parse(menu_is_visible(menu) ? "Black" : "DarkGray", &color); 196 + 197 + if (!sym) 198 + goto set; 199 + 200 + sym_calc_value(sym); 201 + 202 + if (menu->type == M_CHOICE) { // parse children to get a final value 203 + struct symbol *def_sym = sym_calc_choice(menu); 204 + struct menu *def_menu = NULL; 205 + 206 + for (struct menu *child = menu->list; child; child = child->next) { 207 + if (menu_is_visible(child) && child->sym == def_sym) 208 + def_menu = child; 209 + } 210 + 211 + if (def_menu) 212 + value = menu_get_prompt(def_menu); 213 + 214 + goto set; 215 + } 216 + 217 + switch (sym_get_type(sym)) { 218 + case S_BOOLEAN: 219 + case S_TRISTATE: 220 + 221 + btnvis = TRUE; 222 + 223 + val = sym_get_tristate_value(sym); 224 + switch (val) { 225 + case no: 226 + _no = "N"; 227 + value = "N"; 228 + break; 229 + case mod: 230 + _mod = "M"; 231 + value = "M"; 232 + break; 233 + case yes: 234 + _yes = "Y"; 235 + value = "Y"; 236 + break; 237 + } 238 + 239 + if (val != no && sym_tristate_within_range(sym, no)) 240 + _no = "_"; 241 + if (val != mod && sym_tristate_within_range(sym, mod)) 242 + _mod = "_"; 243 + if (val != yes && sym_tristate_within_range(sym, yes)) 244 + _yes = "_"; 245 + break; 246 + default: 247 + value = sym_get_string_value(sym); 248 + editable = TRUE; 249 + break; 250 + } 251 + 252 + set: 253 + gtk_tree_store_set(tree, node, 254 + COL_OPTION, option, 255 + COL_NAME, sym ? sym->name : "", 256 + COL_NO, _no, 257 + COL_MOD, _mod, 258 + COL_YES, _yes, 259 + COL_VALUE, value, 260 + COL_MENU, (gpointer) menu, 261 + COL_COLOR, &color, 262 + COL_EDIT, editable, 263 + COL_PIXBUF, pix_menu, 264 + COL_PIXVIS, view_mode == SINGLE_VIEW && menu->type == M_MENU, 265 + COL_BTNVIS, btnvis, 266 + COL_BTNACT, _yes[0] == 'Y', 267 + COL_BTNINC, _mod[0] == 'M', 268 + COL_BTNRAD, sym && sym_is_choice_value(sym), 269 + -1); 270 + 271 + g_free(option); 272 + } 273 + 174 274 static void _update_tree(GtkTreeStore *store, GtkTreeIter *parent) 175 275 { 176 276 GtkTreeModel *model = GTK_TREE_MODEL(store); ··· 282 186 gtk_tree_model_get(model, &iter, COL_MENU, &menu, -1); 283 187 284 188 if (menu) 285 - set_node(store, &iter, menu, fill_row(menu)); 189 + set_node(store, &iter, menu); 286 190 287 191 _update_tree(store, &iter); 288 192 ··· 661 565 662 566 gtk_widget_destroy(dialog); 663 567 568 + if (!ret) 569 + g_object_unref(pix_menu); 570 + 664 571 return ret; 665 572 } 666 573 ··· 925 826 return FALSE; 926 827 } 927 828 928 - 929 - /* Fill a row of strings */ 930 - static gchar **fill_row(struct menu *menu) 931 - { 932 - static gchar *row[COL_NUMBER]; 933 - struct symbol *sym = menu->sym; 934 - const char *def; 935 - int stype; 936 - tristate val; 937 - enum prop_type ptype; 938 - int i; 939 - 940 - for (i = COL_OPTION; i <= COL_COLOR; i++) 941 - g_free(row[i]); 942 - bzero(row, sizeof(row)); 943 - 944 - ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN; 945 - 946 - row[COL_OPTION] = 947 - g_strdup_printf("%s %s %s %s", 948 - ptype == P_COMMENT ? "***" : "", 949 - menu_get_prompt(menu), 950 - ptype == P_COMMENT ? "***" : "", 951 - sym && !sym_has_value(sym) ? "(NEW)" : ""); 952 - 953 - if (opt_mode == OPT_ALL && !menu_is_visible(menu)) 954 - row[COL_COLOR] = g_strdup("DarkGray"); 955 - else if (opt_mode == OPT_PROMPT && 956 - menu_has_prompt(menu) && !menu_is_visible(menu)) 957 - row[COL_COLOR] = g_strdup("DarkGray"); 958 - else 959 - row[COL_COLOR] = g_strdup("Black"); 960 - 961 - switch (ptype) { 962 - case P_MENU: 963 - row[COL_PIXBUF] = (gchar *) xpm_menu; 964 - if (view_mode == SINGLE_VIEW) 965 - row[COL_PIXVIS] = GINT_TO_POINTER(TRUE); 966 - row[COL_BTNVIS] = GINT_TO_POINTER(FALSE); 967 - break; 968 - case P_COMMENT: 969 - row[COL_PIXBUF] = (gchar *) xpm_void; 970 - row[COL_PIXVIS] = GINT_TO_POINTER(FALSE); 971 - row[COL_BTNVIS] = GINT_TO_POINTER(FALSE); 972 - break; 973 - default: 974 - row[COL_PIXBUF] = (gchar *) xpm_void; 975 - row[COL_PIXVIS] = GINT_TO_POINTER(FALSE); 976 - row[COL_BTNVIS] = GINT_TO_POINTER(TRUE); 977 - break; 978 - } 979 - 980 - if (!sym) 981 - return row; 982 - row[COL_NAME] = g_strdup(sym->name); 983 - 984 - sym_calc_value(sym); 985 - 986 - if (sym_is_choice(sym)) { // parse childs for getting final value 987 - struct menu *child; 988 - struct symbol *def_sym = sym_calc_choice(menu); 989 - struct menu *def_menu = NULL; 990 - 991 - for (child = menu->list; child; child = child->next) { 992 - if (menu_is_visible(child) 993 - && child->sym == def_sym) 994 - def_menu = child; 995 - } 996 - 997 - if (def_menu) 998 - row[COL_VALUE] = 999 - g_strdup(menu_get_prompt(def_menu)); 1000 - 1001 - row[COL_BTNVIS] = GINT_TO_POINTER(FALSE); 1002 - return row; 1003 - } 1004 - if (sym_is_choice_value(sym)) 1005 - row[COL_BTNRAD] = GINT_TO_POINTER(TRUE); 1006 - 1007 - stype = sym_get_type(sym); 1008 - switch (stype) { 1009 - case S_BOOLEAN: 1010 - case S_TRISTATE: 1011 - val = sym_get_tristate_value(sym); 1012 - switch (val) { 1013 - case no: 1014 - row[COL_NO] = g_strdup("N"); 1015 - row[COL_VALUE] = g_strdup("N"); 1016 - row[COL_BTNACT] = GINT_TO_POINTER(FALSE); 1017 - row[COL_BTNINC] = GINT_TO_POINTER(FALSE); 1018 - break; 1019 - case mod: 1020 - row[COL_MOD] = g_strdup("M"); 1021 - row[COL_VALUE] = g_strdup("M"); 1022 - row[COL_BTNINC] = GINT_TO_POINTER(TRUE); 1023 - break; 1024 - case yes: 1025 - row[COL_YES] = g_strdup("Y"); 1026 - row[COL_VALUE] = g_strdup("Y"); 1027 - row[COL_BTNACT] = GINT_TO_POINTER(TRUE); 1028 - row[COL_BTNINC] = GINT_TO_POINTER(FALSE); 1029 - break; 1030 - } 1031 - 1032 - if (val != no && sym_tristate_within_range(sym, no)) 1033 - row[COL_NO] = g_strdup("_"); 1034 - if (val != mod && sym_tristate_within_range(sym, mod)) 1035 - row[COL_MOD] = g_strdup("_"); 1036 - if (val != yes && sym_tristate_within_range(sym, yes)) 1037 - row[COL_YES] = g_strdup("_"); 1038 - break; 1039 - case S_INT: 1040 - case S_HEX: 1041 - case S_STRING: 1042 - def = sym_get_string_value(sym); 1043 - row[COL_VALUE] = g_strdup(def); 1044 - row[COL_EDIT] = GINT_TO_POINTER(TRUE); 1045 - row[COL_BTNVIS] = GINT_TO_POINTER(FALSE); 1046 - break; 1047 - } 1048 - 1049 - return row; 1050 - } 1051 - 1052 - 1053 - /* Set the node content with a row of strings */ 1054 - static void set_node(GtkTreeStore *tree, GtkTreeIter *node, 1055 - struct menu *menu, gchar **row) 1056 - { 1057 - GdkColor color; 1058 - gboolean success; 1059 - GdkPixbuf *pix; 1060 - 1061 - pix = gdk_pixbuf_new_from_xpm_data((const char **) 1062 - row[COL_PIXBUF]); 1063 - 1064 - gdk_color_parse(row[COL_COLOR], &color); 1065 - gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color, 1, 1066 - FALSE, FALSE, &success); 1067 - 1068 - gtk_tree_store_set(tree, node, 1069 - COL_OPTION, row[COL_OPTION], 1070 - COL_NAME, row[COL_NAME], 1071 - COL_NO, row[COL_NO], 1072 - COL_MOD, row[COL_MOD], 1073 - COL_YES, row[COL_YES], 1074 - COL_VALUE, row[COL_VALUE], 1075 - COL_MENU, (gpointer) menu, 1076 - COL_COLOR, &color, 1077 - COL_EDIT, GPOINTER_TO_INT(row[COL_EDIT]), 1078 - COL_PIXBUF, pix, 1079 - COL_PIXVIS, GPOINTER_TO_INT(row[COL_PIXVIS]), 1080 - COL_BTNVIS, GPOINTER_TO_INT(row[COL_BTNVIS]), 1081 - COL_BTNACT, GPOINTER_TO_INT(row[COL_BTNACT]), 1082 - COL_BTNINC, GPOINTER_TO_INT(row[COL_BTNINC]), 1083 - COL_BTNRAD, GPOINTER_TO_INT(row[COL_BTNRAD]), 1084 - -1); 1085 - 1086 - g_object_unref(pix); 1087 - } 1088 - 1089 829 /* Display the whole tree (single/split/full view) */ 1090 830 static void _display_tree(GtkTreeStore *tree, struct menu *menu, 1091 831 GtkTreeIter *parent) ··· 956 1018 continue; 957 1019 958 1020 gtk_tree_store_append(tree, &iter, parent); 959 - set_node(tree, &iter, child, fill_row(child)); 1021 + set_node(tree, &iter, child); 960 1022 961 1023 if ((view_mode != FULL_VIEW) && (ptype == P_MENU) 962 1024 && (tree == tree2)) ··· 1330 1392 COL_COLOR, NULL); 1331 1393 g_signal_connect(G_OBJECT(renderer), "edited", 1332 1394 G_CALLBACK(renderer_edited), tree2_w); 1395 + 1396 + pix_menu = gdk_pixbuf_new_from_xpm_data((const char **)xpm_menu); 1333 1397 1334 1398 for (i = 0; i < COL_VALUE; i++) { 1335 1399 column = gtk_tree_view_get_column(view, i);