mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
js: improve performance of instanceof
against interfaces
This commit is contained in:
parent
19518eb191
commit
188d189407
|
@ -21,15 +21,28 @@ let $rt_isAssignable = (from, to) => {
|
|||
if (from === to) {
|
||||
return true;
|
||||
}
|
||||
let map = from.$meta.assignableCache;
|
||||
if (typeof map === 'undefined') {
|
||||
map = new Map();
|
||||
from.$meta.assignableCache = map;
|
||||
}
|
||||
let cachedResult = map.get(to);
|
||||
if (typeof cachedResult !== 'undefined') {
|
||||
return cachedResult;
|
||||
}
|
||||
if (to.$meta.item !== null) {
|
||||
return from.$meta.item !== null && $rt_isAssignable(from.$meta.item, to.$meta.item);
|
||||
let result = from.$meta.item !== null && $rt_isAssignable(from.$meta.item, to.$meta.item);
|
||||
map.set(to, result);
|
||||
return result;
|
||||
}
|
||||
let supertypes = from.$meta.supertypes;
|
||||
for (let i = 0; i < supertypes.length; i = (i + 1) | 0) {
|
||||
if ($rt_isAssignable(supertypes[i], to)) {
|
||||
map.set(to, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
map.set(to, false);
|
||||
return false;
|
||||
}
|
||||
let $rt_castToInterface = (obj, cls) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user