@@ -406,12 +406,12 @@ async function runPostNativeAnalysis(
406406 * can re-classify roles for the affected implementation files. An empty set
407407 * means no edges were added and role re-classification is unnecessary.
408408 */
409- function runPostNativeCha ( db : BetterSqlite3Database ) : Set < number > {
409+ function runPostNativeCha ( db : BetterSqlite3Database ) : number {
410410 // Fast guard: no hierarchy edges → no CHA work
411411 const hasHierarchy = db
412412 . prepare ( `SELECT 1 FROM edges WHERE kind IN ('extends', 'implements') LIMIT 1` )
413413 . get ( ) ;
414- if ( ! hasHierarchy ) return new Set ( ) ;
414+ if ( ! hasHierarchy ) return 0 ;
415415
416416 // Build implementors map: parent/interface name → [child/implementing class names]
417417 const hierarchyRows = db
@@ -433,7 +433,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
433433 }
434434 if ( ! list . includes ( row . child_name ) ) list . push ( row . child_name ) ;
435435 }
436- if ( implementors . size === 0 ) return new Set ( ) ;
436+ if ( implementors . size === 0 ) return 0 ;
437437
438438 // RTA: collect class names that are actually instantiated via `new X()`.
439439 // Primary query targets `class`-kind nodes (the canonical schema).
@@ -506,7 +506,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
506506 `SELECT id, file AS method_file FROM nodes WHERE name = ? AND kind = 'method'` ,
507507 ) ;
508508 const newEdges : Array < [ number , number , string , number , number , string ] > = [ ] ;
509- const newTargetIds = new Set < number > ( ) ;
509+ let newEdgeCount = 0 ;
510510
511511 for ( const { source_id, method_name, caller_file } of callToMethods ) {
512512 const dotIdx = method_name . indexOf ( '.' ) ;
@@ -545,7 +545,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
545545 CHA_DISPATCH_PENALTY ;
546546 if ( conf <= 0 ) continue ;
547547 newEdges . push ( [ source_id , methodNode . id , 'calls' , conf , 0 , 'cha' ] ) ;
548- newTargetIds . add ( methodNode . id ) ;
548+ newEdgeCount ++ ;
549549 }
550550 }
551551
@@ -558,7 +558,7 @@ function runPostNativeCha(db: BetterSqlite3Database): Set<number> {
558558 if ( newEdges . length > 0 ) {
559559 db . transaction ( ( ) => batchInsertEdges ( db , newEdges ) ) ( ) ;
560560 }
561- return newTargetIds ;
561+ return newEdgeCount ;
562562}
563563
564564/**
@@ -1555,8 +1555,8 @@ export async function tryNativeOrchestrator(
15551555 // pre-CHA might be near the median, but post-CHA the median is higher, changing
15561556 // its role from utility → core.) Using an incremental pass with a stale median
15571557 // cache would produce incorrect roles outside the CHA-affected file set.
1558- const chaTargetIds = runPostNativeCha ( ctx . db as unknown as BetterSqlite3Database ) ;
1559- if ( chaTargetIds . size > 0 ) {
1558+ const chaEdgeCount = runPostNativeCha ( ctx . db as unknown as BetterSqlite3Database ) ;
1559+ if ( chaEdgeCount > 0 ) {
15601560 try {
15611561 const db = ctx . db as unknown as BetterSqlite3Database ;
15621562 const { classifyNodeRoles } = ( await import ( '../../../../features/structure.js' ) ) as {
@@ -1566,7 +1566,7 @@ export async function tryNativeOrchestrator(
15661566 ) => Record < string , number > ;
15671567 } ;
15681568 classifyNodeRoles ( db ) ;
1569- debug ( `CHA post-pass: full role re-classification after ${ chaTargetIds . size } new CHA edges` ) ;
1569+ debug ( `CHA post-pass: full role re-classification after ${ chaEdgeCount } new CHA edges` ) ;
15701570 } catch ( err ) {
15711571 debug ( `CHA post-pass role re-classification failed: ${ toErrorMessage ( err ) } ` ) ;
15721572 }
0 commit comments