perf(ivy): remove check for function type in renderStringify (#30838)
The `renderStringify` function shows up pretty high in the CPU profiling. Turns out that this function contained unnecessary `typeof` check for function types - the check only makes sense / is used in error messages. The PR also alligns how ivy and view engine stringify functions used in interpolations. PR Close #30838
This commit is contained in:
parent
04587a33c5
commit
11a4454ab3
@ -26,7 +26,6 @@ export function isDifferent(a: any, b: any): boolean {
|
|||||||
* be extra careful not to introduce megamorphic reads in it.
|
* be extra careful not to introduce megamorphic reads in it.
|
||||||
*/
|
*/
|
||||||
export function renderStringify(value: any): string {
|
export function renderStringify(value: any): string {
|
||||||
if (typeof value === 'function') return value.name || value;
|
|
||||||
if (typeof value === 'string') return value;
|
if (typeof value === 'string') return value;
|
||||||
if (value == null) return '';
|
if (value == null) return '';
|
||||||
return '' + value;
|
return '' + value;
|
||||||
@ -38,9 +37,10 @@ export function renderStringify(value: any): string {
|
|||||||
* Important! This function contains a megamorphic read and should only be
|
* Important! This function contains a megamorphic read and should only be
|
||||||
* used for error messages.
|
* used for error messages.
|
||||||
*/
|
*/
|
||||||
export function stringifyForError(value: any) {
|
export function stringifyForError(value: any): string {
|
||||||
|
if (typeof value === 'function') return value.name || value.toString();
|
||||||
if (typeof value === 'object' && value != null && typeof value.type === 'function') {
|
if (typeof value === 'object' && value != null && typeof value.type === 'function') {
|
||||||
return value.type.name || value.type;
|
return value.type.name || value.type.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderStringify(value);
|
return renderStringify(value);
|
||||||
|
@ -112,4 +112,20 @@ describe('text instructions', () => {
|
|||||||
|
|
||||||
expect(div.innerHTML).toBe('<h1>LOL, big text</h1>');
|
expect(div.innerHTML).toBe('<h1>LOL, big text</h1>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should stringify functions used in bindings', () => {
|
||||||
|
@Component({
|
||||||
|
template: '<div>{{test}}</div>',
|
||||||
|
})
|
||||||
|
class App {
|
||||||
|
test = function foo() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({declarations: [App]});
|
||||||
|
const fixture = TestBed.createComponent(App);
|
||||||
|
fixture.detectChanges();
|
||||||
|
const div = fixture.nativeElement.querySelector('div');
|
||||||
|
|
||||||
|
expect(div.innerHTML).toBe('function foo() { }');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user