perf(ivy): improve styling performance (#33326)
change the existing implementation from using ``` string.split(/\s+/); ``` to a char scan which performers the same thing. The reason why `split(/\s+/)` is slow is that: - `/\s+/` allocates new `RegExp` every time this code executes. - `RegExp` scans are a lot more expensive because they are more powerful. PR Close #33326
This commit is contained in:

committed by
Andrew Kushnir

parent
c79d6ec502
commit
d40ee6a259
26
packages/core/test/render3/util/styling_utils_spec.ts
Normal file
26
packages/core/test/render3/util/styling_utils_spec.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @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 {splitOnWhitespace} from '@angular/core/src/render3/util/styling_utils';
|
||||
|
||||
describe('styling_utils', () => {
|
||||
describe('splitOnWhitespace', () => {
|
||||
it('should treat empty strings as null', () => {
|
||||
expect(splitOnWhitespace('')).toEqual(null);
|
||||
expect(splitOnWhitespace(' ')).toEqual(null);
|
||||
expect(splitOnWhitespace(' \n\r\t ')).toEqual(null);
|
||||
});
|
||||
|
||||
it('should split strings into parts', () => {
|
||||
expect(splitOnWhitespace('a\nb\rc')).toEqual(['a', 'b', 'c']);
|
||||
expect(splitOnWhitespace('\ta-long\nb-long\rc-long ')).toEqual([
|
||||
'a-long', 'b-long', 'c-long'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user