[vala/staging: 1/2] codegen: Remove unreachable code in TypeRegisterFunction.init_from_type()



commit 7551bbbe8ee6dc9cec3f17436a773f80e5bc2125
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Dec 5 14:08:36 2019 +0100

    codegen: Remove unreachable code in TypeRegisterFunction.init_from_type()
    
    Not used since 79b1a3e39a3d2bac9fbe40c99336b3b89e374571

 codegen/valatyperegisterfunction.vala | 54 ++++++++++-------------------------
 1 file changed, 15 insertions(+), 39 deletions(-)
---
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index 394295f9b..23ab2321a 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -35,7 +35,6 @@ public abstract class Vala.TypeRegisterFunction {
         */
        public void init_from_type (CodeContext context, bool plugin, bool declaration_only) {
                var type_symbol = get_type_declaration ();
-               bool use_thread_safe = !plugin;
 
                bool fundamental = false;
                unowned Class? cl = type_symbol as Class;
@@ -47,20 +46,15 @@ public abstract class Vala.TypeRegisterFunction {
 
                var type_block = new CCodeBlock ();
                CCodeDeclaration cdecl;
-               if (use_thread_safe) {
+               if (!plugin) {
                        cdecl = new CCodeDeclaration ("gsize");
                        cdecl.add_declarator (new CCodeVariableDeclarator (type_id_name + "__volatile", new 
CCodeConstant ("0")));
+                       cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
+                       type_block.add_statement (cdecl);
                } else {
                        cdecl = new CCodeDeclaration ("GType");
                        cdecl.add_declarator (new CCodeVariableDeclarator (type_id_name, new CCodeConstant 
("0")));
-               }
-               cdecl.modifiers = CCodeModifiers.STATIC;
-               if (use_thread_safe) {
-                       cdecl.modifiers |= CCodeModifiers.VOLATILE;
-               }
-               if (!plugin) {
-                       type_block.add_statement (cdecl);
-               } else {
+                       cdecl.modifiers = CCodeModifiers.STATIC;
                        source_declaration_fragment.append (cdecl);
                }
 
@@ -200,7 +194,7 @@ public abstract class Vala.TypeRegisterFunction {
                        reg_call.add_argument (new CCodeConstant (get_type_flags ()));
                }
 
-               if (use_thread_safe && !plugin) {
+               if (!plugin) {
                        var temp_decl = new CCodeDeclaration ("GType");
                        temp_decl.add_declarator (new CCodeVariableDeclarator (type_id_name, reg_call));
                        type_init.add_statement (temp_decl);
@@ -233,38 +227,20 @@ public abstract class Vala.TypeRegisterFunction {
                }
 
                if (!plugin) {
-                       CCodeExpression condition; // the condition that guards the type initialisation
-                       if (use_thread_safe) {
-                               var enter = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_enter"));
-                               enter.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, 
new CCodeIdentifier (type_id_name + "__volatile")));
-                               condition = enter;
-
-                               var leave = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_leave"));
-                               leave.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, 
new CCodeIdentifier (type_id_name + "__volatile")));
-                               leave.add_argument (new CCodeIdentifier (type_id_name));
-                               type_init.add_statement (new CCodeExpressionStatement (leave));
-                       } else {
-                               var id = new CCodeIdentifier (type_id_name);
-                               var zero = new CCodeConstant ("0");
-                               condition = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, id, 
zero);
-                       }
+                       // the condition that guards the type initialisation
+                       var enter = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_enter"));
+                       enter.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new 
CCodeIdentifier (type_id_name + "__volatile")));
 
-                       CCodeExpression cond;
-                       if (use_thread_safe) {
-                               cond = condition;
-                       } else {
-                               cond = new CCodeFunctionCall (new CCodeIdentifier ("G_UNLIKELY"));
-                               ((CCodeFunctionCall) cond).add_argument (condition);
-                       }
-                       var cif = new CCodeIfStatement (cond, type_init);
-                       type_block.add_statement (cif);
-               } else {
-                       type_block = type_init;
-               }
+                       var leave = new CCodeFunctionCall (new CCodeIdentifier ("g_once_init_leave"));
+                       leave.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new 
CCodeIdentifier (type_id_name + "__volatile")));
+                       leave.add_argument (new CCodeIdentifier (type_id_name));
+                       type_init.add_statement (new CCodeExpressionStatement (leave));
 
-               if (use_thread_safe) {
+                       var cif = new CCodeIfStatement (enter, type_init);
+                       type_block.add_statement (cif);
                        type_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier (type_id_name 
+ "__volatile")));
                } else {
+                       type_block = type_init;
                        type_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier 
(type_id_name)));
                }
 


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