Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit bd7d5f6

Browse files
committed
perf($parse): Inline constants
Inline constants definitions in function calls, array definitions and object values. For the expression [1, {foo: "bar"}, 1 + 2] it changes it from ```js // After some reordering and cleanup var v1 = 1; var v2 = "bar"; var v3 = {foo: v2}; var v4 = 1; var v5 = 2; var v6 = plus(v4, v5); var v7 = [v1, v3, v6]; return v7; ``` to ```js return [1, {foo: "bar"}, plus(1, 2)]; ``` Expression parts that are not constants did not change, and still generate a lot of intermediate variables. Closes: #14293
1 parent 3cd00fa commit bd7d5f6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/ng/parse.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ ASTCompiler.prototype = {
924924
case AST.Literal:
925925
expression = this.escape(ast.value);
926926
this.assign(intoId, expression);
927-
recursionFn(expression);
927+
recursionFn(intoId || expression);
928928
break;
929929
case AST.UnaryExpression:
930930
this.recurse(ast.argument, undefined, undefined, function(expr) { right = expr; });
@@ -1046,7 +1046,7 @@ ASTCompiler.prototype = {
10461046
self.if_(self.notNull(right), function() {
10471047
self.addEnsureSafeFunction(right);
10481048
forEach(ast.arguments, function(expr) {
1049-
self.recurse(expr, self.nextId(), undefined, function(argument) {
1049+
self.recurse(expr, ast.constant ? undefined : self.nextId(), undefined, function(argument) {
10501050
args.push(self.ensureSafeObject(argument));
10511051
});
10521052
});
@@ -1087,18 +1087,18 @@ ASTCompiler.prototype = {
10871087
case AST.ArrayExpression:
10881088
args = [];
10891089
forEach(ast.elements, function(expr) {
1090-
self.recurse(expr, self.nextId(), undefined, function(argument) {
1090+
self.recurse(expr, ast.constant ? undefined : self.nextId(), undefined, function(argument) {
10911091
args.push(argument);
10921092
});
10931093
});
10941094
expression = '[' + args.join(',') + ']';
10951095
this.assign(intoId, expression);
1096-
recursionFn(expression);
1096+
recursionFn(intoId || expression);
10971097
break;
10981098
case AST.ObjectExpression:
10991099
args = [];
11001100
forEach(ast.properties, function(property) {
1101-
self.recurse(property.value, self.nextId(), undefined, function(expr) {
1101+
self.recurse(property.value, ast.constant ? undefined : self.nextId(), undefined, function(expr) {
11021102
args.push(self.escape(
11031103
property.key.type === AST.Identifier ? property.key.name :
11041104
('' + property.key.value)) +
@@ -1107,19 +1107,19 @@ ASTCompiler.prototype = {
11071107
});
11081108
expression = '{' + args.join(',') + '}';
11091109
this.assign(intoId, expression);
1110-
recursionFn(expression);
1110+
recursionFn(intoId || expression);
11111111
break;
11121112
case AST.ThisExpression:
11131113
this.assign(intoId, 's');
1114-
recursionFn('s');
1114+
recursionFn(intoId || 's');
11151115
break;
11161116
case AST.LocalsExpression:
11171117
this.assign(intoId, 'l');
1118-
recursionFn('l');
1118+
recursionFn(intoId || 'l');
11191119
break;
11201120
case AST.NGValueParameter:
11211121
this.assign(intoId, 'v');
1122-
recursionFn('v');
1122+
recursionFn(intoId || 'v');
11231123
break;
11241124
}
11251125
},

0 commit comments

Comments
 (0)