@@ -381,8 +381,7 @@ function superposeItem(prev: Stack, b: Bindings, pair: Atom): Item {
381381 return finItem ( prev , pair , b ) ;
382382}
383383
384- function argMask ( env : MinEnv , op : string , arity : number ) : boolean [ ] {
385- const ts = env . sigs . get ( op ) ;
384+ function argMask ( ts : Atom [ ] | undefined , arity : number ) : boolean [ ] {
386385 if ( ts === undefined ) return Array < boolean > ( arity ) . fill ( true ) ;
387386 return Array . from ( { length : arity } , ( _ , i ) => {
388387 const t = ts [ i ] ;
@@ -980,7 +979,12 @@ function mettaEval(
980979 ] ;
981980 }
982981 const queryVars = args . flatMap ( ( x ) => atomVars ( x ) ) ;
983- const mask = argMask ( env , op , args . length ) ;
982+ // Fetch this operator's signature once and reuse it (avoids repeated Map lookups across
983+ // argMask + the per-result returnsAtom check in the reduce loop below).
984+ const sig = env . sigs . get ( op ) ;
985+ const opReturnsAtom =
986+ sig !== undefined && sig . length > 0 && atomEq ( sig [ sig . length - 1 ] ! , sym ( "Atom" ) ) ;
987+ const mask = argMask ( sig , args . length ) ;
984988 // (1) type-directed argument evaluation, binding-threaded
985989 let partials : Array < [ Atom [ ] , Bindings ] > = [ [ [ ] , [ ] ] ] ;
986990 let cur = st ;
@@ -1029,7 +1033,7 @@ function mettaEval(
10291033 const pb = restrictBnd ( queryVars , mergedPb . length > 0 ? mergedPb [ 0 ] ! : p [ 1 ] ) ;
10301034 if ( atomEq ( p [ 0 ] , notReducibleA ) || atomEq ( p [ 0 ] , wApp ) ) {
10311035 out . push ( [ wApp , partB ] ) ;
1032- } else if ( returnsAtom ( env , wApp ) && ! isEmbeddedOp ( p [ 0 ] ) ) {
1036+ } else if ( opReturnsAtom && ! isEmbeddedOp ( p [ 0 ] ) ) {
10331037 out . push ( [ p [ 0 ] , pb ] ) ;
10341038 } else {
10351039 const [ more , st4 ] = mettaEval ( env , fuel - 1 , cur2 , pb , p [ 0 ] ) ;
0 commit comments