]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Remove NamedArgument, improve attribute lookup performance
authorJürg Billeter <j@bitron.ch>
Sun, 26 Oct 2008 21:40:00 +0000 (21:40 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 26 Oct 2008 21:40:00 +0000 (21:40 +0000)
2008-10-26  Jürg Billeter  <j@bitron.ch>

* vala/Makefile.am:
* vala/valaattribute.vala:
* vala/valacodevisitor.vala:
* vala/valafield.vala:
* vala/valagenieparser.vala:
* vala/valanamedargument.vala:
* vala/valaparser.vala:
* vala/valasemanticanalyzer.vala:

Remove NamedArgument, improve attribute lookup performance

svn path=/trunk/; revision=1933

ChangeLog
vala/Makefile.am
vala/valaattribute.vala
vala/valacodevisitor.vala
vala/valafield.vala
vala/valagenieparser.vala
vala/valanamedargument.vala [deleted file]
vala/valaparser.vala
vala/valasemanticanalyzer.vala

index caa022e01e7705cae12704903274f1a576fcdb3c..bfb17df06cfa8257a88427735f8d8d36bda4a02d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-10-26  Jürg Billeter  <j@bitron.ch>
+
+       * vala/Makefile.am:
+       * vala/valaattribute.vala:
+       * vala/valacodevisitor.vala:
+       * vala/valafield.vala:
+       * vala/valagenieparser.vala:
+       * vala/valanamedargument.vala:
+       * vala/valaparser.vala:
+       * vala/valasemanticanalyzer.vala:
+
+       Remove NamedArgument, improve attribute lookup performance
+
 2008-10-26  Jürg Billeter  <j@bitron.ch>
 
        * gobject/valaccodeinvocationexpressionmodule.vala:
index 53340d762d808a8ef52cfecc2cac8265f6a605c7..ad957e80e9a6765ad2608d1cf82c391f4be8b397 100644 (file)
@@ -91,7 +91,6 @@ libvalacore_la_VALASOURCES = \
        valamemberinitializer.vala \
        valamethod.vala \
        valamethodtype.vala \
-       valanamedargument.vala \
        valanamespace.vala \
        valanullchecker.vala \
        valanullliteral.vala \
index 984decdd5cd4eb51655b5374a89dcec50d0b04b3..4144089ec4afa1cb3514de1b66107a36137c4b6d 100644 (file)
@@ -35,7 +35,7 @@ public class Vala.Attribute : CodeNode {
        /**
         * Contains all specified attribute arguments.
         */
-       public Gee.List<NamedArgument> args = new ArrayList<NamedArgument> ();
+       public Gee.Map<string,Expression> args = new Gee.HashMap<string,Expression> (str_hash, str_equal);
 
        /**
         * Creates a new attribute.
@@ -54,8 +54,8 @@ public class Vala.Attribute : CodeNode {
         *
         * @param arg named argument
         */
-       public void add_argument (NamedArgument arg) {
-               args.add (arg);
+       public void add_argument (string key, Expression value) {
+               args.set (key, value);
        }
        
        /**
@@ -65,14 +65,7 @@ public class Vala.Attribute : CodeNode {
         * @return     true if the argument has been found, false otherwise
         */
        public bool has_argument (string name) {
-               // FIXME: use hash table
-               foreach (NamedArgument arg in args) {
-                       if (arg.name == name) {
-                               return true;
-                       }
-               }
-               
-               return false;
+               return args.contains (name);
        }
        
        /**
@@ -82,14 +75,9 @@ public class Vala.Attribute : CodeNode {
         * @return     string value
         */
        public string? get_string (string name) {
-               // FIXME: use hash table
-               foreach (NamedArgument arg in args) {
-                       if (arg.name == name) {
-                               var lit = arg.argument as StringLiteral;
-                               if (lit != null) {
-                                       return lit.eval ();
-                               }
-                       }
+               var lit = args.get (name) as StringLiteral;
+               if (lit != null) {
+                       return lit.eval ();
                }
                
                return null;
@@ -102,14 +90,9 @@ public class Vala.Attribute : CodeNode {
         * @return     integer value
         */
        public int get_integer (string name) {
-               // FIXME: use hash table
-               foreach (NamedArgument arg in args) {
-                       if (arg.name == name) {
-                               var lit = arg.argument as IntegerLiteral;
-                               if (lit != null) {
-                                       return lit.value.to_int ();
-                               }
-                       }
+               var lit = args.get (name) as IntegerLiteral;
+               if (lit != null) {
+                       return lit.value.to_int ();
                }
                
                return 0;
@@ -122,26 +105,22 @@ public class Vala.Attribute : CodeNode {
         * @return     double value
         */
        public double get_double (string name) {
-               // FIXME: use hash table
-               foreach (NamedArgument arg in args) {
-                       if (arg.name == name) {
-                               if (arg.argument is RealLiteral) {
-                                       var lit = (RealLiteral) arg.argument;
-                                       return lit.value.to_double ();
-                               } else if (arg.argument is IntegerLiteral) {
-                                       var lit = (IntegerLiteral) arg.argument;
-                                       return lit.value.to_int ();
-                               } else if (arg.argument is UnaryExpression) {
-                                       var unary = (UnaryExpression) arg.argument;
-                                       if (unary.operator == UnaryOperator.MINUS) {
-                                               if (unary.inner is RealLiteral) {
-                                                       var lit = (RealLiteral) unary.inner;
-                                                       return -lit.value.to_double ();
-                                               } else if (unary.inner is IntegerLiteral) {
-                                                       var lit = (IntegerLiteral) unary.inner;
-                                                       return -lit.value.to_int ();
-                                               }
-                                       }
+               var arg = args.get (name);
+               if (arg is RealLiteral) {
+                       var lit = (RealLiteral) arg;
+                       return lit.value.to_double ();
+               } else if (arg is IntegerLiteral) {
+                       var lit = (IntegerLiteral) arg;
+                       return lit.value.to_int ();
+               } else if (arg is UnaryExpression) {
+                       var unary = (UnaryExpression) arg;
+                       if (unary.operator == UnaryOperator.MINUS) {
+                               if (unary.inner is RealLiteral) {
+                                       var lit = (RealLiteral) unary.inner;
+                                       return -lit.value.to_double ();
+                               } else if (unary.inner is IntegerLiteral) {
+                                       var lit = (IntegerLiteral) unary.inner;
+                                       return -lit.value.to_int ();
                                }
                        }
                }
@@ -156,14 +135,9 @@ public class Vala.Attribute : CodeNode {
         * @return     boolean value
         */
        public bool get_bool (string name) {
-               // FIXME: use hash table
-               foreach (NamedArgument arg in args) {
-                       if (arg.name == name) {
-                               var lit = arg.argument as BooleanLiteral;
-                               if (lit != null) {
-                                       return lit.value;
-                               }
-                       }
+               var lit = args.get (name) as BooleanLiteral;
+               if (lit != null) {
+                       return lit.value;
                }
                
                return false;
index bdaca54aa24c3021f7473dc62574d8a0bbf591ce..a9bd4648a29af3e834a2ddbfd9105647d68caae9 100644 (file)
@@ -195,14 +195,6 @@ public abstract class Vala.CodeVisitor {
        public virtual void visit_destructor (Destructor d) {
        }
 
-       /**
-        * Visit operation called for named arguments.
-        *
-        * @param n a named argument
-        */
-       public virtual void visit_named_argument (NamedArgument n) {
-       }
-
        /**
         * Visit operation called for type parameters.
         *
index b0474f8aa493a758ea416b9ac4a5f7f51472b7fe..7625efa35bee5690ec5b6686ec2a3afc4d562e56 100644 (file)
@@ -195,6 +195,6 @@ public class Vala.Field : Member, Lockable {
                        attr = new Attribute ("CCode");
                        attributes.append (attr);
                }
-               attr.add_argument (new NamedArgument ("type", new StringLiteral ("\"%s\"".printf (ctype))));
+               attr.add_argument ("type", new StringLiteral ("\"%s\"".printf (ctype)));
        }
 }
index 71786d5ce0075021cf2011a372321933ba502b83..21965591371a211303d868d33c9ab0940cb1071f 100644 (file)
@@ -2113,11 +2113,10 @@ public class Vala.Genie.Parser : CodeVisitor {
                                if (accept (TokenType.OPEN_PARENS)) {
                                        if (current () != TokenType.CLOSE_PARENS) {
                                                do {
-                                                       begin = get_location ();
                                                        string id = parse_identifier ();
                                                        expect (TokenType.ASSIGN);
                                                        var expr = parse_expression ();
-                                                       attr.add_argument (new NamedArgument (id, expr, get_src (begin)));
+                                                       attr.add_argument (id, expr);
                                                } while (accept (TokenType.COMMA));
                                        }
                                        expect (TokenType.CLOSE_PARENS);
diff --git a/vala/valanamedargument.vala b/vala/valanamedargument.vala
deleted file mode 100644 (file)
index 3c26899..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/* valanamedargument.vala
- *
- * Copyright (C) 2006-2008  Jürg Billeter
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
-
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
-
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
- *
- * Author:
- *     Jürg Billeter <j@bitron.ch>
- */
-
-using GLib;
-
-/**
- * Represents a named argument in the source code. A named argument may be used
- * when creating objects and attributes where no parameter list exists.
- */
-public class Vala.NamedArgument : CodeNode {
-       /**
-        * The name of a property.
-        */
-       public string name { get; set; }
-       
-       /**
-        * The expression the property should assign.
-        */
-       public Expression argument { get; set; }
-       
-       /**
-        * Creates a new named argument.
-        *
-        * @param name   property name
-        * @param arg    property value expression
-        * @param source reference to source code
-        * @return       newly created named argument
-        */
-       public NamedArgument (string name, Expression argument, SourceReference? source_reference = null) {
-               this.name = name;
-               this.argument = argument;
-               this.source_reference = source_reference;
-       }
-       
-       public override void accept (CodeVisitor visitor) {
-               argument.accept (visitor);
-       
-               visitor.visit_named_argument (this);
-       }
-}
index 8a6de4ea524b40d18fb59f0596572cab6cf442ba..deacc4a9a5bd4c035644c8537b3a2215c08e43e7 100644 (file)
@@ -1665,11 +1665,10 @@ public class Vala.Parser : CodeVisitor {
                                if (accept (TokenType.OPEN_PARENS)) {
                                        if (current () != TokenType.CLOSE_PARENS) {
                                                do {
-                                                       begin = get_location ();
                                                        string id = parse_identifier ();
                                                        expect (TokenType.ASSIGN);
                                                        var expr = parse_expression ();
-                                                       attr.add_argument (new NamedArgument (id, expr, get_src (begin)));
+                                                       attr.add_argument (id, expr);
                                                } while (accept (TokenType.COMMA));
                                        }
                                        expect (TokenType.CLOSE_PARENS);
index 8ad930dca37c3e8942e37d1f01b28255e83e49c3..066d21217fb95e39e640c27300dba5d3ef36dae1 100644 (file)
@@ -764,9 +764,6 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                current_symbol = current_symbol.parent_symbol;
        }
 
-       public override void visit_named_argument (NamedArgument n) {
-       }
-
        public override void visit_block (Block b) {
                b.owner = current_symbol.scope;
                current_symbol = b;