Skip to content

Commit

Permalink
Use list comprehensions in *Evaluate._evaluateArguments
Browse files Browse the repository at this point in the history
As well as being arguably more readable, the toList() method was
running a type check that was showing up as a minor bottleneck in JS
profiles.
  • Loading branch information
nex3 committed Jul 15, 2019
1 parent a8e99e9 commit 58e9e74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 9 additions & 5 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1962,15 +1962,19 @@ class _EvaluateVisitor
{bool trackSpans}) async {
trackSpans ??= _sourceMap;

var positional = (await mapAsync(arguments.positional,
(Expression expression) => expression.accept(this)))
.toList();
var positional = [
for (var expression in arguments.positional) await expression.accept(this)
];
var named = await normalizedMapMapAsync<String, Expression, Value>(
arguments.named,
value: (_, expression) => expression.accept(this));

var positionalNodes =
trackSpans ? arguments.positional.map(_expressionNode).toList() : null;
var positionalNodes = trackSpans
? [
for (var expression in arguments.positional)
_expressionNode(expression)
]
: null;
var namedNodes = trackSpans
? mapMap<String, Expression, String, AstNode>(arguments.named,
value: (_, expression) => _expressionNode(expression))
Expand Down
16 changes: 10 additions & 6 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: cae91fd0fcd94fbb45712286a85761d69fef5415
// Checksum: 1685f0e62002cbb13d3d54ea3d5166c4c7f8f678
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -1949,14 +1949,18 @@ class _EvaluateVisitor
{bool trackSpans}) {
trackSpans ??= _sourceMap;

var positional = arguments.positional
.map((Expression expression) => expression.accept(this))
.toList();
var positional = [
for (var expression in arguments.positional) expression.accept(this)
];
var named = normalizedMapMap<String, Expression, Value>(arguments.named,
value: (_, expression) => expression.accept(this));

var positionalNodes =
trackSpans ? arguments.positional.map(_expressionNode).toList() : null;
var positionalNodes = trackSpans
? [
for (var expression in arguments.positional)
_expressionNode(expression)
]
: null;
var namedNodes = trackSpans
? mapMap<String, Expression, String, AstNode>(arguments.named,
value: (_, expression) => _expressionNode(expression))
Expand Down

0 comments on commit 58e9e74

Please sign in to comment.