[glib: 1/2] glib-compile-resources: encode data as string



commit 0d685b494637775edcb6941706fb047217c48b3f
Author: Ninja-Koala <mail ninjakoa la>
Date:   Wed Aug 22 21:05:17 2018 +0200

    glib-compile-resources: encode data as string
    
    Some Testing revealed encoding resource data with string
    escape codes to compile significantly quicker compared
    to the same data encoded as an array with hexadecimal numbers.
    See #1489

 gio/glib-compile-resources.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index bf88334b1..765cf83ed 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -1087,20 +1087,16 @@ main (int argc, char **argv)
               "# define SECTION\n"
               "#endif\n"
               "\n"
-              "static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; 
void * const ptr;}  %s_resource_data = { {\n",
+              "static const SECTION union { const guint8 data[%"G_GSIZE_FORMAT"]; const double alignment; 
void * const ptr;}  %s_resource_data = {\n  \"",
               c_name_no_underscores, data_size, c_name);
 
       for (i = 0; i < data_size; i++) {
-       if (i % 8 == 0)
-         g_fprintf (file, "  ");
-       g_fprintf (file, "0x%2.2x", (int)data[i]);
-       if (i != data_size - 1)
-         g_fprintf (file, ", ");
-       if ((i % 8 == 7) || (i == data_size - 1))
-         g_fprintf (file, "\n");
+       g_fprintf (file, "\\%3.3o", (int)data[i]);
+       if (i % 16 == 15)
+         g_fprintf (file, "\"\n  \"");
       }
 
-      g_fprintf (file, "} };\n");
+      g_fprintf (file, "\" };\n");
 
       g_fprintf (file,
               "\n"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]