Skip to content
Browse files

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

PR Close #32131
  • Loading branch information...
pkozlowski-opensource authored and AndrewKushnir committed Aug 14, 2019
1 parent de8ebbd commit 4d549f69f8913bf3633f69bf7930bc124f3756fa
@@ -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
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 &&
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
@@ -452,10 +452,10 @@ function executeTemplate<T>(
const prevSelectedIndex = getSelectedIndex();
try {
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 {

0 comments on commit 4d549f6

Please sign in to comment.
You can’t perform that action at this time.