Skip to content

Commit

Permalink
perf(ivy): remove renderStringify calls for text nodes creation (#32342)
Browse files Browse the repository at this point in the history
Values passed to the `ɵɵtext` instruction are strings (or undefined)
in the generated code so no need to stringify those again.

PR Close #32342
  • Loading branch information
pkozlowski-opensource authored and mhevery committed Aug 29, 2019
1 parent fac066e commit a1e91b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
12 changes: 4 additions & 8 deletions packages/core/src/render3/instructions/text.ts
Expand Up @@ -5,15 +5,13 @@
* 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 {assertDataInRange, assertDefined, assertEqual} from '../../util/assert';
import {assertDataInRange, assertEqual} from '../../util/assert';
import {TNodeType} from '../interfaces/node';
import {RText, isProceduralRenderer} from '../interfaces/renderer';
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {BINDING_INDEX, HEADER_OFFSET, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
import {appendChild, createTextNode} from '../node_manipulation';
import {getLView, getSelectedIndex, setIsNotParent} from '../state';
import {NO_CHANGE} from '../tokens';
import {renderStringify} from '../util/misc_utils';
import {getNativeByIndex} from '../util/view_utils';

import {bind} from './property';
import {getOrCreateTNode, textBindingInternal} from './shared';
Expand All @@ -24,19 +22,17 @@ import {getOrCreateTNode, textBindingInternal} from './shared';
* Create static text node
*
* @param index Index of the node in the data array
* @param value Value to write. This value will be stringified.
* @param value Static string value to write.
*
* @codeGenApi
*/
export function ɵɵtext(index: number, value?: any): void {
export function ɵɵtext(index: number, value: string = ''): void {
const lView = getLView();
ngDevMode && assertEqual(
lView[BINDING_INDEX], lView[TVIEW].bindingStartIndex,
'text nodes should be created before any bindings');
ngDevMode && ngDevMode.rendererCreateTextNode++;
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
const textNative = lView[index + HEADER_OFFSET] = createTextNode(value, lView[RENDERER]);
ngDevMode && ngDevMode.rendererSetText++;
const tNode = getOrCreateTNode(lView[TVIEW], lView[T_HOST], index, TNodeType.Element, null, null);

// Text nodes are self closing.
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/render3/node_manipulation.ts
Expand Up @@ -20,7 +20,6 @@ import {ProceduralRenderer3, RElement, RNode, RText, Renderer3, isProceduralRend
import {isLContainer, isLView, isRootView} from './interfaces/type_checks';
import {CHILD_HEAD, CLEANUP, DECLARATION_LCONTAINER, FLAGS, HOST, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, T_HOST, unusedValueExportToPlacateAjd as unused5} from './interfaces/view';
import {assertNodeOfPossibleTypes, assertNodeType} from './node_assert';
import {renderStringify} from './util/misc_utils';
import {findComponentView, getLViewParent} from './util/view_traversal_utils';
import {getNativeByTNode, getNativeByTNodeOrNull, unwrapRNode} from './util/view_utils';

Expand Down Expand Up @@ -116,9 +115,11 @@ function applyToElementOrContainer(
}
}

export function createTextNode(value: any, renderer: Renderer3): RText {
return isProceduralRenderer(renderer) ? renderer.createText(renderStringify(value)) :
renderer.createTextNode(renderStringify(value));
export function createTextNode(value: string, renderer: Renderer3): RText {
ngDevMode && ngDevMode.rendererCreateTextNode++;
ngDevMode && ngDevMode.rendererSetText++;
return isProceduralRenderer(renderer) ? renderer.createText(value) :
renderer.createTextNode(value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/core/core.d.ts
Expand Up @@ -1086,7 +1086,7 @@ export declare function ɵɵtemplate(index: number, templateFn: ComponentTemplat

export declare function ɵɵtemplateRefExtractor(tNode: TNode, currentView: LView): ViewEngine_TemplateRef<unknown> | null;

export declare function ɵɵtext(index: number, value?: any): void;
export declare function ɵɵtext(index: number, value?: string): void;

export declare function ɵɵtextBinding<T>(value: T | NO_CHANGE): void;

Expand Down

0 comments on commit a1e91b0

Please sign in to comment.