mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(compiler): pipeline phase to merge sequential elementstart/elementend (#48580)
As an optimization, the runtime provides an `element()` instruction to use in place of `elementStart()` and `elementEnd()` when there are no instructions between them. This commit merges `ElementStart` and `ElementEnd` IR operations into `Element` operations in that special case. PR Close #48580
This commit is contained in:
parent
199569d9ec
commit
deae02ecef
1 changed files with 30 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as ir from '../../ir';
|
||||
import {ComponentCompilation} from '../compilation';
|
||||
|
||||
/**
|
||||
* Replace sequences of `ElementStart` followed by `ElementEnd` with a condensed `Element`
|
||||
* instruction.
|
||||
*/
|
||||
export function phaseEmptyElements(cpl: ComponentCompilation): void {
|
||||
for (const [_, view] of cpl.views) {
|
||||
for (const op of view.create) {
|
||||
if (op.kind === ir.OpKind.ElementEnd && op.prev !== null &&
|
||||
op.prev.kind === ir.OpKind.ElementStart) {
|
||||
// Transmute the `ElementStart` instruction to `Element`. This is safe as they're designed
|
||||
// to be identical apart from the `kind`.
|
||||
(op.prev as unknown as ir.ElementOp).kind = ir.OpKind.Element;
|
||||
|
||||
// Remove the `ElementEnd` instruction.
|
||||
ir.OpList.remove<ir.CreateOp>(op);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue