Skip to content

Commit b092eee

Browse files
committed
#6876 manager.ClassHierarchy: isAQueryMap => Memoizes the return values of isA() calls
1 parent e7c4931 commit b092eee

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/manager/ClassHierarchy.mjs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class ClassHierarchy extends BaseManager {
2424
singleton: true
2525
}
2626

27+
/**
28+
* Memoizes the return values of isA() calls
29+
* @member {Map} isAQueryMap=new Map()
30+
* @protected
31+
*/
32+
isAQueryMap = new Map()
33+
2734
/**
2835
* @param {Object} config
2936
*/
@@ -58,25 +65,36 @@ class ClassHierarchy extends BaseManager {
5865
return true
5966
}
6067

61-
let parent = descendant;
68+
let parent = descendant,
69+
{isAQueryMap} = this,
70+
queryName = `${descendant},${ancestor}`,
71+
returnValue = false;
72+
73+
if (isAQueryMap.has(queryName)) {
74+
return isAQueryMap.get(queryName)
75+
}
6276

6377
while (parent = this.get(parent)?.parentClassName) {console.log(parent);
6478
if (parent === ancestor) {
65-
return true
79+
returnValue = true;
80+
break
6681
}
6782

6883
// Assumption: component.Base directly extends core.Base
6984
if (parent === 'Neo.component.Base' && ancestor !== 'Neo.core.Base') {
70-
return false
85+
returnValue = false;
86+
break
7187
}
7288

7389
if (parent === 'Neo.core.Base') {
74-
return false
90+
returnValue = false;
91+
break
7592
}
7693
}
7794

78-
// Cover wrong inputs
79-
return false
95+
isAQueryMap.set(queryName, returnValue);
96+
97+
return returnValue
8098
}
8199
}
82100

0 commit comments

Comments
 (0)