]> git.draconx.ca Git - gob-dx.git/blobdiff - src/main.c
Release 2.0.4
[gob-dx.git] / src / main.c
index d22a7da7a9a6262d6201d590fefc1e60832d54cc..f74f89775a288a562e9010673149822c16b7e069 100644 (file)
@@ -1059,7 +1059,7 @@ add_get_type(void)
                   "%s_get_type (void)\n"
                   "{\n"
                   "\tstatic GType type = 0;\n\n"
-                  "\tif (type == 0) {\n"
+                  "\tif ___GOB_UNLIKELY(type == 0) {\n"
                   "\t\tstatic const GTypeInfo info = {\n"
                   "\t\t\tsizeof (%sClass),\n"
                   "\t\t\t(GBaseInitFunc) NULL,\n"
@@ -1112,7 +1112,7 @@ add_bonobo_object_get_type (void)
                    "%s_get_type (void)\n" /* 1 */
                    "{\n"
                    "\tstatic GType type = 0;\n\n"
-                   "\tif (type == 0) {\n"
+                   "\tif ___GOB_UNLIKELY(type == 0) {\n"
                    "\t\tstatic const GTypeInfo info = {\n"
                    "\t\t\tsizeof (%sClass),\n" /* 2 */
                    "\t\t\t(GBaseInitFunc) NULL,\n"
@@ -1314,7 +1314,7 @@ add_signals(Class *c)
                   ! is_none) {
                        GList *gl, *al;
                        const char *sep = "";
-                       out_printf(out, "\tif(");
+                       out_printf(out, "\tif ___GOB_UNLIKELY(");
                        if(strcmp(m->gtktypes->data, "NONE") != 0) {
                                out_printf(out, "%s sizeof(", sep);
                                print_type(out, m->mtype, FALSE);
@@ -3281,7 +3281,7 @@ print_class_block(Class *c)
                    " */\n");
 
        if ( ! overrode_get_type) {
-               out_printf (outh, "GType\t%s_get_type\t(void);", funcbase);
+               out_printf (outh, "GType\t%s_get_type\t(void);\n", funcbase);
        }
 
        for(li = c->nodes; li != NULL; li = li->next) {
@@ -3423,6 +3423,23 @@ print_useful_macros(void)
        out_printf (out, "#define selfp (self->_priv)\n\n");
 }
 
+static void
+print_more_useful_macros (void)
+{
+       if (no_gnu) {
+               out_printf (out, "#define ___GOB_LIKELY(expr) (expr)\n");
+               out_printf (out, "#define ___GOB_UNLIKELY(expr) (expr)\n");
+       } else {
+               out_printf (out, "#ifdef G_LIKELY\n");
+               out_printf (out, "#define ___GOB_LIKELY(expr) G_LIKELY(expr)\n");
+               out_printf (out, "#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)\n");
+               out_printf (out, "#else /* ! G_LIKELY */\n");
+               out_printf (out, "#define ___GOB_LIKELY(expr) (expr)\n");
+               out_printf (out, "#define ___GOB_UNLIKELY(expr) (expr)\n");
+               out_printf (out, "#endif /* G_LIKELY */\n");
+       }
+}
+
 static void
 print_file_comments(void)
 {
@@ -3615,7 +3632,7 @@ print_enum (EnumDef *enode)
                    "GType\n%s_get_type (void)\n"
                    "{\n"
                    "\tstatic GType type = 0;\n"
-                   "\tif (type == 0)\n"
+                   "\tif ___GOB_UNLIKELY(type == 0)\n"
                    "\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
                    "\treturn type;\n"
                    "}\n\n",
@@ -3680,7 +3697,7 @@ print_flags (Flags *fnode)
                    "GType\n%s_get_type (void)\n"
                    "{\n"
                    "\tstatic GType type = 0;\n"
-                   "\tif (type == 0)\n"
+                   "\tif ___GOB_UNLIKELY(type == 0)\n"
                    "\t\ttype = g_flags_register_static (\"%s\", _%s_values);\n"
                    "\treturn type;\n"
                    "}\n\n",
@@ -3743,7 +3760,7 @@ print_error (Error *enode)
                    "GType\n%s_get_type (void)\n"
                    "{\n"
                    "\tstatic GType type = 0;\n"
-                   "\tif (type == 0)\n"
+                   "\tif ___GOB_UNLIKELY(type == 0)\n"
                    "\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
                    "\treturn type;\n"
                    "}\n\n",
@@ -3788,6 +3805,8 @@ generate_outfiles(void)
 
        print_includes();
 
+       print_more_useful_macros ();
+
        for (li = nodes; li != NULL; li = li->next) {
                Node *node = li->data;
                if (node->type == CCODE_NODE) {