perf(ivy): auto-call select(0) for non-empty views only (#32131)

PR Close #32131
This commit is contained in:
Pawel Kozlowski 2019-08-14 10:44:29 +02:00 committed by Andrew Kushnir
parent de8ebbdfd0
commit 4d549f69f8
2 changed files with 8 additions and 11 deletions

View File

@ -5,7 +5,7 @@
* 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 {assertGreaterThan, assertLessThan} from '../../util/assert';
import {assertDataInRange, assertGreaterThan} from '../../util/assert';
import {executePreOrderHooks} from '../hooks';
import {HEADER_OFFSET, LView, TVIEW} from '../interfaces/view';
import {getCheckNoChangesMode, getLView, setSelectedIndex} from '../state';
@ -33,18 +33,15 @@ import {getCheckNoChangesMode, getLView, setSelectedIndex} from '../state';
* @codeGenApi
*/
export function ɵɵselect(index: number): void {
ngDevMode && assertGreaterThan(index, -1, 'Invalid index');
ngDevMode &&
assertLessThan(
index, getLView().length - HEADER_OFFSET, 'Should be within range for the view data');
const lView = getLView();
selectInternal(lView, index);
selectInternal(getLView(), index, getCheckNoChangesMode());
}
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.
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
// that cause other template functions to run, thus updating the selected index, which is global

View File

@ -452,10 +452,10 @@ function executeTemplate<T>(
const prevSelectedIndex = getSelectedIndex();
try {
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
// instruction for most update blocks
selectInternal(lView, 0);
selectInternal(lView, 0, getCheckNoChangesMode());
}
templateFn(rf, context);
} finally {