Skip to content

Commit 1e3399e

Browse files
committed
compute children list once on object construction
1 parent 61a2e77 commit 1e3399e

File tree

14 files changed

+40
-26
lines changed

14 files changed

+40
-26
lines changed

benchmarks/Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ Apple M1 Pro, 1 CPU, 10 logical and 10 physical cores
1111
```
1212
| Method | Job | Runtime | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
1313
|--------|---------------|---------------|---------:|----------:|----------:|----------:|---------:|----------:|
14-
| Invoke | .NET 9.0 | .NET 9.0 | 7.427 ms | 0.1477 ms | 0.1701 ms | 1593.7500 | 406.2500 | 9.57 MB |
15-
| Invoke | NativeAOT 9.0 | NativeAOT 9.0 | 7.215 ms | 0.0836 ms | 0.0699 ms | 1593.7500 | 453.1250 | 9.56 MB |
14+
| Invoke | .NET 9.0 | .NET 9.0 | 9.525 ms | 0.1615 ms | 0.1658 ms | 1562.5000 | 500.0000 | 9.37 MB |
15+
| Invoke | NativeAOT 9.0 | NativeAOT 9.0 | 7.321 ms | 0.0544 ms | 0.0509 ms | 1562.5000 | 468.7500 | 9.36 MB |

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Declarations/AfterTypesAreLoaded/FunctionDeclaration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class FunctionDeclaration : AfterTypesAreLoadedDeclaration
99
{
1010
private readonly List<IFunctionArgument> _arguments;
1111

12-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children => [Statements];
12+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
1313

1414
public IdentifierReference Name { get; }
1515
public TypeValue ReturnTypeValue { get; }
@@ -32,6 +32,7 @@ public FunctionDeclaration(
3232

3333
Statements = blockStatement;
3434
Statements.Parent = this;
35+
Children = [Statements];
3536

3637
ReturnStatements = Statements
3738
.GetAllNodes()

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/AssignmentExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
55
[AutoVisitable<IAbstractSyntaxTreeNode>]
66
public partial class AssignmentExpression : Expression
77
{
8-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
9-
[Destination, Source];
8+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
109

1110
public LeftHandSideExpression Destination { get; }
1211
public Expression Source { get; }
@@ -24,6 +23,8 @@ public AssignmentExpression(
2423
source.Parent = this;
2524

2625
DestinationType = destinationType;
26+
27+
Children = [Destination, Source];
2728
}
2829

2930
/// <inheritdoc cref="AbstractSyntaxTreeNode.InitScope"/>

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/BinaryExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
33
[AutoVisitable<IAbstractSyntaxTreeNode>]
44
public partial class BinaryExpression : Expression
55
{
6-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
7-
[Left, Right];
6+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
87

98
public Expression Left { get; }
109
public string Operator { get; }
@@ -19,6 +18,8 @@ public BinaryExpression(Expression left, string @operator, Expression right)
1918

2019
Right = right;
2120
Right.Parent = this;
21+
22+
Children = [Left, Right];
2223
}
2324

2425
protected override string NodeRepresentation() => Operator;

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/CallExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public partial class CallExpression : LeftHandSideExpression
77
{
88
private readonly List<Expression> _parameters;
99

10-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
11-
[Member, .._parameters];
10+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
1211

1312
public MemberExpression Member { get; }
1413
public IReadOnlyList<Expression> Parameters => _parameters;
@@ -25,6 +24,8 @@ public CallExpression(MemberExpression member, List<Expression> expressions)
2524

2625
_parameters = expressions;
2726
_parameters.ForEach(expr => expr.Parent = this);
27+
28+
Children = [Member, .._parameters];
2829
}
2930

3031
public override IdentifierReference Id => Member.Id;

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/CastAsExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
55
[AutoVisitable<IAbstractSyntaxTreeNode>]
66
public partial class CastAsExpression : Expression
77
{
8-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
9-
[Expression];
8+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
109

1110
public Expression Expression { get; }
1211
public TypeValue Cast { get; }
@@ -17,6 +16,8 @@ public CastAsExpression(Expression expression, TypeValue cast)
1716
Expression.Parent = this;
1817

1918
Cast = cast;
19+
20+
Children = [Expression];
2021
}
2122

2223
/// <inheritdoc cref="AbstractSyntaxTreeNode.InitScope"/>

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/ComplexLiterals/Property.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions.ComplexL
55
[AutoVisitable<IAbstractSyntaxTreeNode>]
66
public partial class Property : Expression
77
{
8-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
9-
[Id, Expression];
8+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
109

1110
public IdentifierReference Id { get; }
1211
public Expression Expression { get; }
@@ -21,6 +20,8 @@ public Property(IdentifierReference id, Expression expression)
2120

2221
Expression = expression;
2322
Expression.Parent = this;
23+
24+
Children = [Id, Expression];
2425
}
2526

2627
public void Deconstruct(out string id, out Expression expr)

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/ConditionalExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
33
[AutoVisitable<IAbstractSyntaxTreeNode>]
44
public partial class ConditionalExpression : Expression
55
{
6-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
7-
[Test, Consequent, Alternate];
6+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
87

98
public Expression Test { get; }
109
public Expression Consequent { get; }
@@ -19,6 +18,8 @@ public ConditionalExpression(Expression test, Expression consequent, Expression
1918
Test.Parent = this;
2019
Consequent.Parent = this;
2120
Alternate.Parent = this;
21+
22+
Children = [Test, Consequent, Alternate];
2223
}
2324

2425
protected override string NodeRepresentation() => "?:";

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Expressions/UnaryExpression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Expressions;
33
[AutoVisitable<IAbstractSyntaxTreeNode>]
44
public partial class UnaryExpression : Expression
55
{
6-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
7-
[Expression];
6+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
87

98
public string Operator { get; }
109
public Expression Expression { get; }
@@ -15,6 +14,8 @@ public UnaryExpression(string @operator, Expression expression)
1514

1615
Expression = expression;
1716
Expression.Parent = this;
17+
18+
Children = [Expression];
1819
}
1920

2021
protected override string NodeRepresentation() => Operator;

src/Domain/HydraScript.Domain.FrontEnd/Parser/Impl/Ast/Nodes/Statements/ExpressionStatement.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ namespace HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Statements;
33
[AutoVisitable<IAbstractSyntaxTreeNode>]
44
public partial class ExpressionStatement : Statement
55
{
6-
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children =>
7-
[Expression];
6+
protected override IReadOnlyList<IAbstractSyntaxTreeNode> Children { get; }
87

98
public Expression Expression { get; }
109

1110
public ExpressionStatement(Expression expression)
1211
{
1312
Expression = expression;
1413
Expression.Parent = this;
14+
15+
Children = [Expression];
1516
}
1617

1718
protected override string NodeRepresentation() => nameof(ExpressionStatement);

0 commit comments

Comments
 (0)