perf(ivy): improve NaN checks in change detection (#32212)
This commit drops our custom, change-detection specific, equality comparison util in favour of the standard Object.is which has desired semantics. There are multiple advantages of this approach: - less code to maintain on our end; - avoid NaN checks if both values are equal; - re-write NaN checks so we don't trigger V8 deoptimizations. PR Close #32212
This commit is contained in:

committed by
Andrew Kushnir

parent
53f33c1cec
commit
53bfa7c6d6
@ -1010,9 +1010,6 @@
|
||||
{
|
||||
"name": "isDevMode"
|
||||
},
|
||||
{
|
||||
"name": "isDifferent"
|
||||
},
|
||||
{
|
||||
"name": "isFactory"
|
||||
},
|
||||
|
@ -1,68 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* 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 {devModeEqual} from '@angular/core/src/change_detection/change_detection_util';
|
||||
import {isDifferent} from '../../src/render3/util/misc_utils';
|
||||
|
||||
describe('util', () => {
|
||||
|
||||
describe('isDifferent', () => {
|
||||
|
||||
describe('checkNoChangeMode = false', () => {
|
||||
it('should mark non-equal arguments as different', () => {
|
||||
expect(isDifferent({}, {})).toBeTruthy();
|
||||
expect(isDifferent('foo', 'bar')).toBeTruthy();
|
||||
expect(isDifferent(0, 1)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not mark equal arguments as different', () => {
|
||||
const obj = {};
|
||||
expect(isDifferent(obj, obj)).toBeFalsy();
|
||||
expect(isDifferent('foo', 'foo')).toBeFalsy();
|
||||
expect(isDifferent(1, 1)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); });
|
||||
|
||||
it('should mark NaN with other values as different', () => {
|
||||
expect(isDifferent(NaN, 'foo')).toBeTruthy();
|
||||
expect(isDifferent(5, NaN)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkNoChangeMode = true', () => {
|
||||
// Assert relaxed constraint in checkNoChangeMode
|
||||
it('should not mark non-equal arrays, object and function as different', () => {
|
||||
expect(!devModeEqual([], [])).toBeFalsy();
|
||||
expect(!devModeEqual(() => 0, () => 0)).toBeFalsy();
|
||||
expect(!devModeEqual({}, {})).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should mark non-equal arguments as different', () => {
|
||||
expect(!devModeEqual('foo', 'bar')).toBeTruthy();
|
||||
expect(!devModeEqual(0, 1)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not mark equal arguments as different', () => {
|
||||
const obj = {};
|
||||
expect(isDifferent(obj, obj)).toBeFalsy();
|
||||
expect(isDifferent('foo', 'foo')).toBeFalsy();
|
||||
expect(isDifferent(1, 1)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); });
|
||||
|
||||
it('should mark NaN with other values as different', () => {
|
||||
expect(isDifferent(NaN, 'foo')).toBeTruthy();
|
||||
expect(isDifferent(5, NaN)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user