mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 17:23:37 +08:00
refactor(managed): share unresolved type name cache writes (#17406)
This commit is contained in:
@@ -239,6 +239,10 @@ export const managedMetadataTypeNames = (
|
||||
for (const { row, type } of parsedTypes.types) definitions.set(row, type);
|
||||
}
|
||||
const cache = new Map<string, ResolvedTypeName | null>();
|
||||
const cacheUnresolved = (key: string): null => {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
};
|
||||
const depthLimit = Symbol("type-name-depth-limit");
|
||||
const resolve = (
|
||||
table: 1 | 2,
|
||||
@@ -250,10 +254,7 @@ export const managedMetadataTypeNames = (
|
||||
const descriptor = layout.table(table);
|
||||
if (descriptor === undefined || row < 1 || row > descriptor.rowCount)
|
||||
return null;
|
||||
if (active.has(key)) {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (active.has(key)) return cacheUnresolved(key);
|
||||
if (active.size >= MAX_TYPE_NESTING_DEPTH) return depthLimit;
|
||||
managedDecodeBudget(layout).reserve(128, null);
|
||||
let name: string;
|
||||
@@ -261,21 +262,14 @@ export const managedMetadataTypeNames = (
|
||||
let parentRow: number | null;
|
||||
if (table === 1) {
|
||||
const reference = references(row);
|
||||
if (reference === null || !reference.scopeValid) {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (reference === null || !reference.scopeValid)
|
||||
return cacheUnresolved(key);
|
||||
({ name, namespace, enclosingRow: parentRow } = reference);
|
||||
} else {
|
||||
if (!nesting.complete) {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (!nesting.complete) return cacheUnresolved(key);
|
||||
const parsed = definitions.get(row);
|
||||
if (parsedTypes !== undefined && parsed === undefined) {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (parsedTypes !== undefined && parsed === undefined)
|
||||
return cacheUnresolved(key);
|
||||
let flags: number;
|
||||
if (parsed !== undefined) {
|
||||
name = parsed.name;
|
||||
@@ -295,10 +289,7 @@ export const managedMetadataTypeNames = (
|
||||
}
|
||||
parentRow = nesting.enclosing.get(row) ?? null;
|
||||
const isNested = (flags & 0x7) >= 2;
|
||||
if (isNested !== (parentRow !== null)) {
|
||||
cache.set(key, null);
|
||||
return null;
|
||||
}
|
||||
if (isNested !== (parentRow !== null)) return cacheUnresolved(key);
|
||||
}
|
||||
let fullName: string | null;
|
||||
let depth = 1;
|
||||
|
||||
Reference in New Issue
Block a user