Add a fast path for checking for exact node types.
In my unscientific tests locally, this look the time for generating 200 files down from 11.8 to 8.3 seconds.
This commit is contained in:
parent
e7d37f342c
commit
e7796b45c9
@ -96,6 +96,10 @@ export function is(type: string, node: Object, opts?: Object): boolean {
|
||||
export function isType(nodeType: string, targetType: string): boolean {
|
||||
if (nodeType === targetType) return true;
|
||||
|
||||
// This is a fast-path. If the test above failed, but an alias key is found, then the
|
||||
// targetType was a primary node type, so there's no need to check the aliases.
|
||||
if (t.ALIAS_KEYS[targetType]) return false;
|
||||
|
||||
let aliases: ?Array<string> = t.FLIPPED_ALIAS_KEYS[targetType];
|
||||
if (aliases) {
|
||||
if (aliases[0] === nodeType) return true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user