Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
c79d6ec
commit d40ee6a
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
]); | ||
}); | ||
}); | ||
}); |