From: Jürg Billeter Date: Sun, 26 Oct 2008 21:40:00 +0000 (+0000) Subject: Remove NamedArgument, improve attribute lookup performance X-Git-Tag: VALA_0_5_1~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cec33e591ada9eb65bfe03a05d0afbcadaa9686;p=thirdparty%2Fvala.git Remove NamedArgument, improve attribute lookup performance 2008-10-26 Jürg Billeter * 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 --- diff --git a/ChangeLog b/ChangeLog index caa022e01..bfb17df06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-10-26 Jürg Billeter + + * 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 * gobject/valaccodeinvocationexpressionmodule.vala: diff --git a/vala/Makefile.am b/vala/Makefile.am index 53340d762..ad957e80e 100644 --- a/vala/Makefile.am +++ b/vala/Makefile.am @@ -91,7 +91,6 @@ libvalacore_la_VALASOURCES = \ valamemberinitializer.vala \ valamethod.vala \ valamethodtype.vala \ - valanamedargument.vala \ valanamespace.vala \ valanullchecker.vala \ valanullliteral.vala \ diff --git a/vala/valaattribute.vala b/vala/valaattribute.vala index 984decdd5..4144089ec 100644 --- a/vala/valaattribute.vala +++ b/vala/valaattribute.vala @@ -35,7 +35,7 @@ public class Vala.Attribute : CodeNode { /** * Contains all specified attribute arguments. */ - public Gee.List args = new ArrayList (); + public Gee.Map args = new Gee.HashMap (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; diff --git a/vala/valacodevisitor.vala b/vala/valacodevisitor.vala index bdaca54aa..a9bd4648a 100644 --- a/vala/valacodevisitor.vala +++ b/vala/valacodevisitor.vala @@ -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. * diff --git a/vala/valafield.vala b/vala/valafield.vala index b0474f8aa..7625efa35 100644 --- a/vala/valafield.vala +++ b/vala/valafield.vala @@ -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))); } } diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index 71786d5ce..219655913 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -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 index 3c2689916..000000000 --- a/vala/valanamedargument.vala +++ /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 - */ - -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); - } -} diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 8a6de4ea5..deacc4a9a 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -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); diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 8ad930dca..066d21217 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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;