]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Do not use temp var when accessing single-assignment locals
authorJürg Billeter <j@bitron.ch>
Mon, 1 Aug 2011 19:14:34 +0000 (21:14 +0200)
committerJürg Billeter <j@bitron.ch>
Mon, 1 Aug 2011 19:18:00 +0000 (21:18 +0200)
codegen/valaccodememberaccessmodule.vala
vala/valaflowanalyzer.vala
vala/valavariable.vala

index 6abce487213379b568f2ca5593474a25769ced1c..4e428fbe4b8e948aa8a965c9e74a164789f35f07 100644 (file)
@@ -689,7 +689,22 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                }
                result.value_type.value_owned = false;
 
-               if (!(variable is Parameter && variable.name == "this") && is_lvalue_access_allowed (result.value_type)) {
+               bool use_temp = true;
+               if (!is_lvalue_access_allowed (result.value_type)) {
+                       // special handling for types such as va_list
+                       use_temp = false;
+               }
+               if (variable is Parameter && variable.name == "this") {
+                       use_temp = false;
+               }
+               if (variable.single_assignment && !result.value_type.is_real_struct_type ()) {
+                       // no need to copy values from variables that are exactly once
+                       // as there is no risk of modification
+                       // except for structs that are always passed by reference
+                       use_temp = false;
+               }
+
+               if (use_temp) {
                        result = (GLibValue) store_temp_value (result, variable);
                }
 
index 87d6728f96d78194125b9c8b6b876634e0953700..ada3254d3ffd43d87a9a3dedc1a5903cc51a31f8 100644 (file)
@@ -514,6 +514,9 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                if (variable_stack == null) {
                        variable_stack = new ArrayList<Variable> ();
                        var_map.set (var_symbol, variable_stack);
+                       var_symbol.single_assignment = true;
+               } else {
+                       var_symbol.single_assignment = false;
                }
                Variable versioned_var;
                if (var_symbol is LocalVariable) {
index 9337751e18df2ac5cc5f6859955dce0fcc58b5e3..e625e660bba7890c52d314addadb74f68f9d0bfa 100644 (file)
@@ -49,6 +49,8 @@ public class Vala.Variable : Symbol {
                }
        }
 
+       public bool single_assignment { get; set; }
+
        Expression? _initializer;
        DataType? _variable_type;