perf: Use indexed lookup in extractPascalDefProc instead of linear scan
Replace this.nodes.find() with a lazily-built Map<name, nodeId> for matching implementation bodies to their declarations. Reduces per-file complexity from O(methods × nodes) to O(nodes) for index build + O(1) per lookup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
f414ed7e3e
commit
5a279d3132
@@ -887,6 +887,7 @@ export class TreeSitterExtractor {
|
|||||||
private errors: ExtractionError[] = [];
|
private errors: ExtractionError[] = [];
|
||||||
private extractor: LanguageExtractor | null = null;
|
private extractor: LanguageExtractor | null = null;
|
||||||
private nodeStack: string[] = []; // Stack of parent node IDs
|
private nodeStack: string[] = []; // Stack of parent node IDs
|
||||||
|
private methodIndex: Map<string, string> | null = null; // name → node ID for defProc lookup
|
||||||
|
|
||||||
constructor(filePath: string, source: string, language?: Language) {
|
constructor(filePath: string, source: string, language?: Language) {
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
@@ -2331,12 +2332,17 @@ export class TreeSitterExtractor {
|
|||||||
// fullName is like "TAuthService.Create" — we want just the method name part
|
// fullName is like "TAuthService.Create" — we want just the method name part
|
||||||
const shortName = fullName.includes('.') ? fullName.split('.').pop()! : fullName;
|
const shortName = fullName.includes('.') ? fullName.split('.').pop()! : fullName;
|
||||||
|
|
||||||
// Find matching node from earlier extraction
|
// Build method index on first use (O(n) once, then O(1) per lookup)
|
||||||
const existingNode = this.nodes.find(
|
if (!this.methodIndex) {
|
||||||
(n) => n.name === shortName && (n.kind === 'method' || n.kind === 'function')
|
this.methodIndex = new Map();
|
||||||
);
|
for (const n of this.nodes) {
|
||||||
|
if (n.kind === 'method' || n.kind === 'function') {
|
||||||
|
this.methodIndex.set(n.name, n.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const parentId = existingNode?.id || this.nodeStack[this.nodeStack.length - 1];
|
const parentId = this.methodIndex.get(shortName) || this.nodeStack[this.nodeStack.length - 1];
|
||||||
if (!parentId) return;
|
if (!parentId) return;
|
||||||
|
|
||||||
// Visit the block for calls
|
// Visit the block for calls
|
||||||
|
|||||||
Reference in New Issue
Block a user