perf(ivy): avoid for-of loops at runtime (#32157)
TypeScript downlevels `for-of` loops for ES5 targets. As a result, generated output contains extra code, including a try-catch block, which has code size and performance implications. This is especially important for runtime code where we want to keep it as small as possible. This commit changes `for-of` loops in runtime code to regular `for` loops. PR Close #32157
This commit is contained in:
parent
43163523f6
commit
abb44f7db0
@ -95,7 +95,8 @@ export function ɵɵInheritDefinitionFeature(definition: DirectiveDef<any>| Comp
|
|||||||
// Run parent features
|
// Run parent features
|
||||||
const features = superDef.features;
|
const features = superDef.features;
|
||||||
if (features) {
|
if (features) {
|
||||||
for (const feature of features) {
|
for (let i = 0; i < features.length; i++) {
|
||||||
|
const feature = features[i];
|
||||||
if (feature && feature.ngInherit) {
|
if (feature && feature.ngInherit) {
|
||||||
(feature as DirectiveDefFeature)(definition);
|
(feature as DirectiveDefFeature)(definition);
|
||||||
}
|
}
|
||||||
|
@ -91,13 +91,13 @@ class TQueries_ implements TQueries {
|
|||||||
elementStart(tView: TView, tNode: TNode): void {
|
elementStart(tView: TView, tNode: TNode): void {
|
||||||
ngDevMode && assertFirstTemplatePass(
|
ngDevMode && assertFirstTemplatePass(
|
||||||
tView, 'Queries should collect results on the first template pass only');
|
tView, 'Queries should collect results on the first template pass only');
|
||||||
for (let query of this.queries) {
|
for (let i = 0; i < this.queries.length; i++) {
|
||||||
query.elementStart(tView, tNode);
|
this.queries[i].elementStart(tView, tNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elementEnd(tNode: TNode): void {
|
elementEnd(tNode: TNode): void {
|
||||||
for (let query of this.queries) {
|
for (let i = 0; i < this.queries.length; i++) {
|
||||||
query.elementEnd(tNode);
|
this.queries[i].elementEnd(tNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
embeddedTView(tNode: TNode): TQueries|null {
|
embeddedTView(tNode: TNode): TQueries|null {
|
||||||
@ -123,8 +123,8 @@ class TQueries_ implements TQueries {
|
|||||||
template(tView: TView, tNode: TNode): void {
|
template(tView: TView, tNode: TNode): void {
|
||||||
ngDevMode && assertFirstTemplatePass(
|
ngDevMode && assertFirstTemplatePass(
|
||||||
tView, 'Queries should collect results on the first template pass only');
|
tView, 'Queries should collect results on the first template pass only');
|
||||||
for (let query of this.queries) {
|
for (let i = 0; i < this.queries.length; i++) {
|
||||||
query.template(tView, tNode);
|
this.queries[i].template(tView, tNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +367,9 @@ function collectQueryResults<T>(lView: LView, queryIndex: number, result: T[]):
|
|||||||
// collect matches for views created from this declaration container and inserted into
|
// collect matches for views created from this declaration container and inserted into
|
||||||
// different containers
|
// different containers
|
||||||
if (declarationLContainer[MOVED_VIEWS] !== null) {
|
if (declarationLContainer[MOVED_VIEWS] !== null) {
|
||||||
for (let embeddedLView of declarationLContainer[MOVED_VIEWS] !) {
|
const embeddedLViews = declarationLContainer[MOVED_VIEWS] !;
|
||||||
collectQueryResults(embeddedLView, childQueryIndex, result);
|
for (let i = 0; i < embeddedLViews.length; i++) {
|
||||||
|
collectQueryResults(embeddedLViews[i], childQueryIndex, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user