perf(ivy): cache multiple reads to an element's stylingContext (#29818)

Because the styling context may be stored in a different location
and be apart of a sub array, reading the styling context each time
a host binding is evaluated is costly. This patch ensures that the
active styling context is cached so that multiple interactions with
styling bindings can easily retrieve the styling context efficiently.

PR Close #29818
This commit is contained in:
Matias Niemelä
2019-04-10 11:54:59 -07:00
committed by Alex Rickabaugh
parent 9147092a15
commit 2deac0a412
10 changed files with 102 additions and 29 deletions

View File

@ -13,6 +13,7 @@ import {executeHooks} from './hooks';
import {ComponentDef, DirectiveDef} from './interfaces/definition';
import {TElementNode, TNode, TViewNode} from './interfaces/node';
import {BINDING_INDEX, CONTEXT, DECLARATION_VIEW, FLAGS, InitPhaseState, LView, LViewFlags, OpaqueViewState, TVIEW} from './interfaces/view';
import {setCachedStylingContext} from './styling/state';
import {resetPreOrderHookFlags} from './util/view_utils';
@ -456,6 +457,7 @@ export function leaveView(newView: LView): void {
lView[BINDING_INDEX] = tView.bindingStartIndex;
}
}
setCachedStylingContext(null);
enterView(newView, null);
}
@ -482,6 +484,10 @@ export function getSelectedIndex() {
*/
export function setSelectedIndex(index: number) {
_selectedIndex = index;
// remove the styling context from the cache
// because we are now on a different element
setCachedStylingContext(null);
}