From nobody Wed Oct 8 22:37:19 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C13382F3C02; Tue, 24 Jun 2025 15:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750777733; cv=none; b=Xw3nIyvWkhuIIYNLF3xVC52soLFXDwC/Yz4BA+gv3uMlM15A9XTNwokTTnsRVovVfI4YzxLig+hFWebdeM5JuWKD2bD1+NgCePx1TVj8xp393rnhLwcnmC7Apkbec0zHIPACnVExby1rLMie2WPbPf0FQROJ7gydPOuChkHcVyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750777733; c=relaxed/simple; bh=824f8DlEQgSpnKuIo6VOnt4KdtWe09eG9Iq5JKNcA5Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UzpdmJ1huJw+vivxRwXBWCbdiVggV0I9oTTq2M34kx0o4KLp3Vhb3Q4nrwp282yytyuGRSh6UY1ZGSo6Y1xIdZQUX1dBH0TgLDSzJqgWaCn+fCldyKSQSLYMRQ/+P0+alWo8NMEmc3l2hbWNbC/USE1JlAsYU94PG01BqS6W+zw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bToGsVnl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bToGsVnl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63AB4C4CEF3; Tue, 24 Jun 2025 15:08:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750777733; bh=824f8DlEQgSpnKuIo6VOnt4KdtWe09eG9Iq5JKNcA5Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bToGsVnlDrldMN/c/S4MSB0PccHJWCVOoyXCP5WUJKixgUeCXJIKI6tDNnX2mJfyb yCepNOO0PUZJiRJKw8QQFDoacFclifQTskcMvZWGGQSiVR6VZmG+6H28lrvL/t5pj0 ojutSlSi7LzbOtaCGRoL26fEjmijUBpO98UhR7wG9giJgYIWEPFHp7eX5QmzqeK5W9 qAaQJIDkNztdHp4puidd1aoEVCtbugade9Ej/JR3t391MHcephPagsNqaiYQNK5t8K Ob/pbjMiYgqnDda1Z7OiycXa8L21D6YhRJWHIPuhZ4YIJ0t7qB9EFhWgRMebI6vvda zYawMgkBZCh+Q== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 47/66] kconfig: gconf: inline fill_row() into set_node() Date: Wed, 25 Jun 2025 00:05:35 +0900 Message-ID: <20250624150645.1107002-48-masahiroy@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250624150645.1107002-1-masahiroy@kernel.org> References: <20250624150645.1107002-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- scripts/kconfig/gconf.c | 272 ++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 166 deletions(-) diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c index 0977d906bea6..0b73ba9eca14 100644 --- a/scripts/kconfig/gconf.c +++ b/scripts/kconfig/gconf.c @@ -44,6 +44,7 @@ static GtkWidget *save_menu_item; static GtkTextTag *tag1, *tag2; =20 static GtkTreeStore *tree1, *tree2; +static GdkPixbuf *pix_menu; =20 static struct menu *browsed; // browsed menu for SINGLE/SPLIT view static struct menu *selected; // selected entry @@ -58,9 +59,6 @@ enum { static void display_list(void); static void display_tree(GtkTreeStore *store, struct menu *menu); static void display_tree_part(void); -static gchar **fill_row(struct menu *menu); -static void set_node(GtkTreeStore *tree, GtkTreeIter *node, - struct menu *menu, gchar **row); =20 static void conf_changed(bool dirty) { @@ -125,6 +123,104 @@ static void update_row_visibility(void) _update_row_visibility(GTK_TREE_VIEW(tree2_w)); } =20 +static void set_node(GtkTreeStore *tree, GtkTreeIter *node, struct menu *m= enu) +{ + struct symbol *sym =3D menu->sym; + tristate val; + gchar *option; + const gchar *_no =3D ""; + const gchar *_mod =3D ""; + const gchar *_yes =3D ""; + const gchar *value =3D ""; + GdkColor color; + gboolean editable =3D FALSE; + gboolean btnvis =3D FALSE; + + option =3D g_strdup_printf("%s %s %s %s", + menu->type =3D=3D M_COMMENT ? "***" : "", + menu_get_prompt(menu), + menu->type =3D=3D M_COMMENT ? "***" : "", + sym && !sym_has_value(sym) ? "(NEW)" : ""); + + gdk_color_parse(menu_is_visible(menu) ? "Black" : "DarkGray", &color); + + if (!sym) + goto set; + + sym_calc_value(sym); + + if (menu->type =3D=3D M_CHOICE) { // parse children to get a final value + struct symbol *def_sym =3D sym_calc_choice(menu); + struct menu *def_menu =3D NULL; + + for (struct menu *child =3D menu->list; child; child =3D child->next) { + if (menu_is_visible(child) && child->sym =3D=3D def_sym) + def_menu =3D child; + } + + if (def_menu) + value =3D menu_get_prompt(def_menu); + + goto set; + } + + switch (sym_get_type(sym)) { + case S_BOOLEAN: + case S_TRISTATE: + + btnvis =3D TRUE; + + val =3D sym_get_tristate_value(sym); + switch (val) { + case no: + _no =3D "N"; + value =3D "N"; + break; + case mod: + _mod =3D "M"; + value =3D "M"; + break; + case yes: + _yes =3D "Y"; + value =3D "Y"; + break; + } + + if (val !=3D no && sym_tristate_within_range(sym, no)) + _no =3D "_"; + if (val !=3D mod && sym_tristate_within_range(sym, mod)) + _mod =3D "_"; + if (val !=3D yes && sym_tristate_within_range(sym, yes)) + _yes =3D "_"; + break; + default: + value =3D sym_get_string_value(sym); + editable =3D TRUE; + break; + } + +set: + gtk_tree_store_set(tree, node, + COL_OPTION, option, + COL_NAME, sym ? sym->name : "", + COL_NO, _no, + COL_MOD, _mod, + COL_YES, _yes, + COL_VALUE, value, + COL_MENU, (gpointer) menu, + COL_COLOR, &color, + COL_EDIT, editable, + COL_PIXBUF, pix_menu, + COL_PIXVIS, view_mode =3D=3D SINGLE_VIEW && menu->type =3D=3D M_MENU, + COL_BTNVIS, btnvis, + COL_BTNACT, _yes[0] =3D=3D 'Y', + COL_BTNINC, _mod[0] =3D=3D 'M', + COL_BTNRAD, sym && sym_is_choice_value(sym), + -1); + + g_free(option); +} + static void _update_tree(GtkTreeStore *store, GtkTreeIter *parent) { GtkTreeModel *model =3D GTK_TREE_MODEL(store); @@ -138,7 +234,7 @@ static void _update_tree(GtkTreeStore *store, GtkTreeIt= er *parent) gtk_tree_model_get(model, &iter, COL_MENU, &menu, -1); =20 if (menu) - set_node(store, &iter, menu, fill_row(menu)); + set_node(store, &iter, menu); =20 _update_tree(store, &iter); =20 @@ -563,6 +659,9 @@ static gboolean on_window1_delete_event(GtkWidget *widg= et, GdkEvent *event, =20 gtk_widget_destroy(dialog); =20 + if (!ret) + g_object_unref(pix_menu); + return ret; } =20 @@ -824,167 +923,6 @@ static gboolean on_treeview1_button_press_event(GtkWi= dget *widget, return FALSE; } =20 - -/* Fill a row of strings */ -static gchar **fill_row(struct menu *menu) -{ - static gchar *row[COL_NUMBER]; - struct symbol *sym =3D menu->sym; - const char *def; - int stype; - tristate val; - enum prop_type ptype; - int i; - - for (i =3D COL_OPTION; i <=3D COL_COLOR; i++) - g_free(row[i]); - bzero(row, sizeof(row)); - - ptype =3D menu->prompt ? menu->prompt->type : P_UNKNOWN; - - row[COL_OPTION] =3D - g_strdup_printf("%s %s %s %s", - ptype =3D=3D P_COMMENT ? "***" : "", - menu_get_prompt(menu), - ptype =3D=3D P_COMMENT ? "***" : "", - sym && !sym_has_value(sym) ? "(NEW)" : ""); - - if (opt_mode =3D=3D OPT_ALL && !menu_is_visible(menu)) - row[COL_COLOR] =3D g_strdup("DarkGray"); - else if (opt_mode =3D=3D OPT_PROMPT && - menu_has_prompt(menu) && !menu_is_visible(menu)) - row[COL_COLOR] =3D g_strdup("DarkGray"); - else - row[COL_COLOR] =3D g_strdup("Black"); - - switch (ptype) { - case P_MENU: - row[COL_PIXBUF] =3D (gchar *) xpm_menu; - if (view_mode =3D=3D SINGLE_VIEW) - row[COL_PIXVIS] =3D GINT_TO_POINTER(TRUE); - row[COL_BTNVIS] =3D GINT_TO_POINTER(FALSE); - break; - case P_COMMENT: - row[COL_PIXBUF] =3D (gchar *) xpm_void; - row[COL_PIXVIS] =3D GINT_TO_POINTER(FALSE); - row[COL_BTNVIS] =3D GINT_TO_POINTER(FALSE); - break; - default: - row[COL_PIXBUF] =3D (gchar *) xpm_void; - row[COL_PIXVIS] =3D GINT_TO_POINTER(FALSE); - row[COL_BTNVIS] =3D GINT_TO_POINTER(TRUE); - break; - } - - if (!sym) - return row; - row[COL_NAME] =3D g_strdup(sym->name); - - sym_calc_value(sym); - - if (sym_is_choice(sym)) { // parse childs for getting final value - struct menu *child; - struct symbol *def_sym =3D sym_calc_choice(menu); - struct menu *def_menu =3D NULL; - - for (child =3D menu->list; child; child =3D child->next) { - if (menu_is_visible(child) - && child->sym =3D=3D def_sym) - def_menu =3D child; - } - - if (def_menu) - row[COL_VALUE] =3D - g_strdup(menu_get_prompt(def_menu)); - - row[COL_BTNVIS] =3D GINT_TO_POINTER(FALSE); - return row; - } - if (sym_is_choice_value(sym)) - row[COL_BTNRAD] =3D GINT_TO_POINTER(TRUE); - - stype =3D sym_get_type(sym); - switch (stype) { - case S_BOOLEAN: - case S_TRISTATE: - val =3D sym_get_tristate_value(sym); - switch (val) { - case no: - row[COL_NO] =3D g_strdup("N"); - row[COL_VALUE] =3D g_strdup("N"); - row[COL_BTNACT] =3D GINT_TO_POINTER(FALSE); - row[COL_BTNINC] =3D GINT_TO_POINTER(FALSE); - break; - case mod: - row[COL_MOD] =3D g_strdup("M"); - row[COL_VALUE] =3D g_strdup("M"); - row[COL_BTNINC] =3D GINT_TO_POINTER(TRUE); - break; - case yes: - row[COL_YES] =3D g_strdup("Y"); - row[COL_VALUE] =3D g_strdup("Y"); - row[COL_BTNACT] =3D GINT_TO_POINTER(TRUE); - row[COL_BTNINC] =3D GINT_TO_POINTER(FALSE); - break; - } - - if (val !=3D no && sym_tristate_within_range(sym, no)) - row[COL_NO] =3D g_strdup("_"); - if (val !=3D mod && sym_tristate_within_range(sym, mod)) - row[COL_MOD] =3D g_strdup("_"); - if (val !=3D yes && sym_tristate_within_range(sym, yes)) - row[COL_YES] =3D g_strdup("_"); - break; - case S_INT: - case S_HEX: - case S_STRING: - def =3D sym_get_string_value(sym); - row[COL_VALUE] =3D g_strdup(def); - row[COL_EDIT] =3D GINT_TO_POINTER(TRUE); - row[COL_BTNVIS] =3D GINT_TO_POINTER(FALSE); - break; - } - - return row; -} - - -/* Set the node content with a row of strings */ -static void set_node(GtkTreeStore *tree, GtkTreeIter *node, - struct menu *menu, gchar **row) -{ - GdkColor color; - gboolean success; - GdkPixbuf *pix; - - pix =3D gdk_pixbuf_new_from_xpm_data((const char **) - row[COL_PIXBUF]); - - gdk_color_parse(row[COL_COLOR], &color); - gdk_colormap_alloc_colors(gdk_colormap_get_system(), &color, 1, - FALSE, FALSE, &success); - - gtk_tree_store_set(tree, node, - COL_OPTION, row[COL_OPTION], - COL_NAME, row[COL_NAME], - COL_NO, row[COL_NO], - COL_MOD, row[COL_MOD], - COL_YES, row[COL_YES], - COL_VALUE, row[COL_VALUE], - COL_MENU, (gpointer) menu, - COL_COLOR, &color, - COL_EDIT, GPOINTER_TO_INT(row[COL_EDIT]), - COL_PIXBUF, pix, - COL_PIXVIS, GPOINTER_TO_INT(row[COL_PIXVIS]), - COL_BTNVIS, GPOINTER_TO_INT(row[COL_BTNVIS]), - COL_BTNACT, GPOINTER_TO_INT(row[COL_BTNACT]), - COL_BTNINC, GPOINTER_TO_INT(row[COL_BTNINC]), - COL_BTNRAD, GPOINTER_TO_INT(row[COL_BTNRAD]), - -1); - - g_object_unref(pix); -} - /* Display the whole tree (single/split/full view) */ static void _display_tree(GtkTreeStore *tree, struct menu *menu, GtkTreeIter *parent) @@ -1016,7 +954,7 @@ static void _display_tree(GtkTreeStore *tree, struct m= enu *menu, continue; =20 gtk_tree_store_append(tree, &iter, parent); - set_node(tree, &iter, child, fill_row(child)); + set_node(tree, &iter, child); =20 if ((view_mode !=3D FULL_VIEW) && (ptype =3D=3D P_MENU) && (tree =3D=3D tree2)) @@ -1384,6 +1322,8 @@ static void init_right_tree(void) g_signal_connect(G_OBJECT(renderer), "edited", G_CALLBACK(renderer_edited), tree2_w); =20 + pix_menu =3D gdk_pixbuf_new_from_xpm_data((const char **)xpm_menu); + for (i =3D 0; i < COL_VALUE; i++) { column =3D gtk_tree_view_get_column(view, i); gtk_tree_view_column_set_resizable(column, TRUE); --=20 2.43.0