perf(ivy): auto-call select(0) for non-empty views only (#32131)
PR Close #32131
This commit is contained in:
parent
de8ebbdfd0
commit
4d549f69f8
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {assertGreaterThan, assertLessThan} from '../../util/assert';
|
import {assertDataInRange, assertGreaterThan} from '../../util/assert';
|
||||||
import {executePreOrderHooks} from '../hooks';
|
import {executePreOrderHooks} from '../hooks';
|
||||||
import {HEADER_OFFSET, LView, TVIEW} from '../interfaces/view';
|
import {HEADER_OFFSET, LView, TVIEW} from '../interfaces/view';
|
||||||
import {getCheckNoChangesMode, getLView, setSelectedIndex} from '../state';
|
import {getCheckNoChangesMode, getLView, setSelectedIndex} from '../state';
|
||||||
|
@ -33,18 +33,15 @@ import {getCheckNoChangesMode, getLView, setSelectedIndex} from '../state';
|
||||||
* @codeGenApi
|
* @codeGenApi
|
||||||
*/
|
*/
|
||||||
export function ɵɵselect(index: number): void {
|
export function ɵɵselect(index: number): void {
|
||||||
ngDevMode && assertGreaterThan(index, -1, 'Invalid index');
|
selectInternal(getLView(), index, getCheckNoChangesMode());
|
||||||
ngDevMode &&
|
|
||||||
assertLessThan(
|
|
||||||
index, getLView().length - HEADER_OFFSET, 'Should be within range for the view data');
|
|
||||||
const lView = getLView();
|
|
||||||
selectInternal(lView, index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function selectInternal(lView: LView, index: number, checkNoChangesMode: boolean) {
|
||||||
|
ngDevMode && assertGreaterThan(index, -1, 'Invalid index');
|
||||||
|
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
||||||
|
|
||||||
export function selectInternal(lView: LView, index: number) {
|
|
||||||
// Flush the initial hooks for elements in the view that have been added up to this point.
|
// Flush the initial hooks for elements in the view that have been added up to this point.
|
||||||
executePreOrderHooks(lView, lView[TVIEW], getCheckNoChangesMode(), index);
|
executePreOrderHooks(lView, lView[TVIEW], checkNoChangesMode, index);
|
||||||
|
|
||||||
// We must set the selected index *after* running the hooks, because hooks may have side-effects
|
// We must set the selected index *after* running the hooks, because hooks may have side-effects
|
||||||
// that cause other template functions to run, thus updating the selected index, which is global
|
// that cause other template functions to run, thus updating the selected index, which is global
|
||||||
|
|
|
@ -452,10 +452,10 @@ function executeTemplate<T>(
|
||||||
const prevSelectedIndex = getSelectedIndex();
|
const prevSelectedIndex = getSelectedIndex();
|
||||||
try {
|
try {
|
||||||
setActiveHostElement(null);
|
setActiveHostElement(null);
|
||||||
if (rf & RenderFlags.Update) {
|
if (rf & RenderFlags.Update && lView.length > HEADER_OFFSET) {
|
||||||
// When we're updating, have an inherent ɵɵselect(0) so we don't have to generate that
|
// When we're updating, have an inherent ɵɵselect(0) so we don't have to generate that
|
||||||
// instruction for most update blocks
|
// instruction for most update blocks
|
||||||
selectInternal(lView, 0);
|
selectInternal(lView, 0, getCheckNoChangesMode());
|
||||||
}
|
}
|
||||||
templateFn(rf, context);
|
templateFn(rf, context);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue