Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
7b68ef7669 widget-factory: Precompile the ui file
It doesn't make a huge amount of difference, unfortunately.
2021-09-19 20:19:34 -04:00
Matthias Clasen
11b9b1759a buildertool: Add a compile command
This converts the ui file into our internal, precompiled,
format. The widget-factory.ui file shrinks from 200k to 45k.
But sadly, the loading time only shrinks from 240ms to 235.
2021-09-19 20:19:34 -04:00
6 changed files with 118 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gtk/WidgetFactory4">
<file preprocess="xml-stripblanks">widget-factory.ui</file>
<file alias='widget-factory.ui'>widget-factory.uic</file>
</gresource>
<gresource prefix="/org/gtk/WidgetFactory4">
<file>widget-factory.css</file>

Binary file not shown.

View File

@@ -0,0 +1,110 @@
/* Copyright 2015 Red Hat, Inc.
*
* GTK+ is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* GLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GTK+; see the file COPYING. If not,
* see <http://www.gnu.org/licenses/>.
*
* Author: Matthias Clasen
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <glib/gi18n.h>
#include <glib/gprintf.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include "gtkbuilderprivate.h"
#include "gtk-builder-tool.h"
static void
compile_file (const char *input,
const char *output)
{
GtkBuilder *builder;
char *text;
gsize len;
GError *error = NULL;
GBytes *bytes;
if (!g_file_get_contents (input, &text, &len, &error))
{
g_printerr ("%s\n", error->message);
exit (1);
}
builder = gtk_builder_new ();
bytes = _gtk_buildable_parser_precompile (text, len, &error);
if (!bytes)
{
g_printerr ("%s\n", error->message);
exit (1);
}
if (!g_file_set_contents (output,
g_bytes_get_data (bytes, NULL),
g_bytes_get_size (bytes),
&error))
{
g_printerr ("%s\n", error->message);
exit (1);
}
g_bytes_unref (bytes);
g_object_unref (builder);
g_free (text);
}
void
do_compile (int *argc,
const char ***argv)
{
GOptionContext *context;
char **filenames = NULL;
const GOptionEntry entries[] = {
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL },
{ NULL, }
};
GError *error = NULL;
context = g_option_context_new (NULL);
g_option_context_set_help_enabled (context, FALSE);
g_option_context_add_main_entries (context, entries, NULL);
if (!g_option_context_parse (context, argc, (char ***)argv, &error))
{
g_printerr ("%s\n", error->message);
g_error_free (error);
exit (1);
}
g_option_context_free (context);
if (filenames == NULL)
{
g_printerr ("No .ui file specified\n");
exit (1);
}
if (g_strv_length (filenames) != 2)
{
g_printerr ("Need to specify an output file\n");
exit (1);
}
compile_file (filenames[0], filenames[1]);
g_strfreev (filenames);
}

View File

@@ -39,6 +39,8 @@ usage (void)
" simplify Simplify the file\n"
" enumerate List all named objects\n"
" preview Preview the file\n"
" compile Compile the file\n"
" into a compact format\n"
"\n"
"Simplify Options:\n"
" --replace Replace the file\n"
@@ -134,6 +136,8 @@ main (int argc, const char *argv[])
do_enumerate (&argc, &argv);
else if (strcmp (argv[0], "preview") == 0)
do_preview (&argc, &argv);
else if (strcmp (argv[0], "compile") == 0)
do_compile (&argc, &argv);
else
usage ();

View File

@@ -6,5 +6,6 @@ void do_simplify (int *argc, const char ***argv);
void do_validate (int *argc, const char ***argv);
void do_enumerate (int *argc, const char ***argv);
void do_preview (int *argc, const char ***argv);
void do_compile (int *argc, const char ***argv);
#endif

View File

@@ -28,7 +28,8 @@ gtk_tools = [
'gtk-builder-tool-simplify.c',
'gtk-builder-tool-validate.c',
'gtk-builder-tool-enumerate.c',
'gtk-builder-tool-preview.c'], [libgtk_dep] ],
'gtk-builder-tool-compile.c',
'gtk-builder-tool-preview.c'], [libgtk_static_dep] ],
['gtk4-update-icon-cache', ['updateiconcache.c'] + extra_update_icon_cache_objs, [ libgtk_static_dep ] ],
['gtk4-encode-symbolic-svg', ['encodesymbolic.c'], [ libgtk_static_dep ] ],
]