From a06043b703ee9ea11c56912f1478340b80ad1031 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Wed, 7 Aug 2019 17:13:59 +0200 Subject: [PATCH] perf(ivy): remove global state access from setUpAttributes (#32041) PR Close #32041 --- packages/core/src/render3/instructions/element.ts | 4 ++-- packages/core/src/render3/util/attrs_utils.ts | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/core/src/render3/instructions/element.ts b/packages/core/src/render3/instructions/element.ts index 6a7fa36047..e9197f14e8 100644 --- a/packages/core/src/render3/instructions/element.ts +++ b/packages/core/src/render3/instructions/element.ts @@ -58,7 +58,7 @@ export function ɵɵelementStart( getOrCreateTNode(tView, lView[T_HOST], index, TNodeType.Element, name, attrs || null); if (attrs != null) { - const lastAttrIndex = setUpAttributes(native, attrs); + const lastAttrIndex = setUpAttributes(renderer, native, attrs); if (tView.firstTemplatePass) { registerInitialStylingOnTNode(tNode, attrs, lastAttrIndex); } @@ -209,7 +209,7 @@ export function ɵɵelementHostAttrs(attrs: TAttributes) { // errors... if (tNode.type === TNodeType.Element) { const native = getNativeByTNode(tNode, lView) as RElement; - const lastAttrIndex = setUpAttributes(native, attrs); + const lastAttrIndex = setUpAttributes(lView[RENDERER], native, attrs); if (tView.firstTemplatePass) { const stylingNeedsToBeRendered = registerInitialStylingOnTNode(tNode, attrs, lastAttrIndex); diff --git a/packages/core/src/render3/util/attrs_utils.ts b/packages/core/src/render3/util/attrs_utils.ts index f01be94688..6249d6adf9 100644 --- a/packages/core/src/render3/util/attrs_utils.ts +++ b/packages/core/src/render3/util/attrs_utils.ts @@ -7,9 +7,7 @@ */ import {AttributeMarker, TAttributes} from '../interfaces/node'; import {CssSelector} from '../interfaces/projection'; -import {ProceduralRenderer3, RElement, isProceduralRenderer} from '../interfaces/renderer'; -import {RENDERER} from '../interfaces/view'; -import {getLView} from '../state'; +import {ProceduralRenderer3, RElement, Renderer3, isProceduralRenderer} from '../interfaces/renderer'; /** @@ -34,13 +32,12 @@ import {getLView} from '../state'; * Note that this instruction does not support assigning style and class values to * an element. See `elementStart` and `elementHostAttrs` to learn how styling values * are applied to an element. - * + * @param renderer The renderer to be used * @param native The element that the attributes will be assigned to * @param attrs The attribute array of values that will be assigned to the element * @returns the index value that was last accessed in the attributes array */ -export function setUpAttributes(native: RElement, attrs: TAttributes): number { - const renderer = getLView()[RENDERER]; +export function setUpAttributes(renderer: Renderer3, native: RElement, attrs: TAttributes): number { const isProc = isProceduralRenderer(renderer); let i = 0;