optimize access to automatic properties, patch by Rob Taylor
authorJuerg Billeter <j@bitron.ch>
Sat, 8 Mar 2008 16:55:29 +0000 (16:55 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sat, 8 Mar 2008 16:55:29 +0000 (16:55 +0000)
2008-03-08  Juerg Billeter  <j@bitron.ch>

* vala/valaclass.vala, vala/valaproperty.vala,
  vala/valapropertyaccessor.vala, vala/valasemanticanalyzer.vala,
  gobject/valaccodegeneratormemberaccess.vala: optimize access to
  automatic properties, patch by Rob Taylor

svn path=/trunk/; revision=1110

ChangeLog
gobject/valaccodegeneratormemberaccess.vala
vala/valaclass.vala
vala/valaproperty.vala
vala/valapropertyaccessor.vala
vala/valasemanticanalyzer.vala

index b5115b4..7b271d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-03-08  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valaclass.vala, vala/valaproperty.vala,
+         vala/valapropertyaccessor.vala, vala/valasemanticanalyzer.vala,
+         gobject/valaccodegeneratormemberaccess.vala: optimize access to
+         automatic properties, patch by Rob Taylor
+
+2008-03-08  Jürg Billeter  <j@bitron.ch>
+
        * gobject/valaccodegenerator.vala: support foreach over
          multi-dimensional arrays
 
index 89e0ed2..4c1a709 100644 (file)
@@ -105,7 +105,13 @@ public class Vala.CCodeGenerator {
                } else if (expr.symbol_reference is Property) {
                        var prop = (Property) expr.symbol_reference;
 
-                       if (!prop.no_accessor_method) {
+                       if (prop.get_accessor != null &&
+                           prop.get_accessor.automatic_body &&
+                           current_type_symbol == prop.parent_symbol) {
+                               CCodeExpression inst;
+                               inst = new CCodeMemberAccess.pointer (pub_inst, "priv");
+                               expr.ccodenode = new CCodeMemberAccess.pointer (inst, prop.field.get_cname());
+                       } else if (!prop.no_accessor_method) {
                                var base_property = prop;
                                if (prop.base_property != null) {
                                        base_property = prop.base_property;
index 516d81e..8e0eacc 100644 (file)
@@ -263,6 +263,7 @@ public class Vala.Class : Typesymbol {
                                var field_type = prop.type_reference.copy ();
                                var f = new Field ("_%s".printf (prop.name), field_type, prop.default_expression, prop.source_reference);
                                f.access = SymbolAccessibility.PRIVATE;
+                               prop.field = f;
                                add_field (f);
                        }
                }
index dbf0079..f52486f 100644 (file)
@@ -90,6 +90,11 @@ public class Vala.Property : Member, Lockable {
        public bool overrides { get; set; }
 
        /**
+        * Reference the the Field that holds this property
+        */
+       public Field field { get; set; }
+
+       /**
         * Specifies whether this field may only be accessed with an instance of
         * the contained type.
         */
index cd0857d..0b0d4bf 100644 (file)
@@ -62,6 +62,11 @@ public class Vala.PropertyAccessor : CodeNode {
        public BasicBlock exit_block { get; set; }
 
        /**
+        * True if the body was automatically generated
+        */
+       public bool automatic_body { get; set; }
+
+       /**
         * Represents the generated value parameter in a set accessor.
         */
        public FormalParameter value_parameter { get; set; }
index ce5eb66..8155341 100644 (file)
@@ -650,7 +650,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                        Report.error (acc.source_reference, "Automatic properties can't be used in interfaces");
                                        return;
                                }
-
+                               acc.automatic_body = true;
                                acc.body = new Block ();
                                if (acc.readable) {
                                        acc.body.add_statement (new ReturnStatement (new MemberAccess.simple ("_%s".printf (acc.prop.name)), acc.source_reference));