@@ -716,9 +716,8 @@ export class Series<T extends Scalar = Scalar> {
716716 const vals = this . _values ;
717717
718718 // Pre-partition NaN/null/undefined from finite values in one pass.
719- // fvals mirrors finBuf: fvals[j] holds the numeric value at finBuf[j]
720- // so the sort comparator reads a typed Float64Array (not a generic T[]),
721- // giving the JIT a monomorphic, unboxed call site.
719+ // fvals stores numeric values by original row index so the sort comparator
720+ // can read a typed Float64Array (not a generic T[]) at index a/b.
722721 const finBuf = new Uint32Array ( n ) ;
723722 const nanBuf = new Uint32Array ( n ) ;
724723 const fvals = new Float64Array ( n ) ;
@@ -731,7 +730,7 @@ export class Series<T extends Scalar = Scalar> {
731730 nanBuf [ nanCount ++ ] = i ;
732731 } else {
733732 if ( typeof v === "number" ) {
734- fvals [ finCount ] = v ;
733+ fvals [ i ] = v ;
735734 } else {
736735 allNumeric = false ;
737736 }
@@ -744,12 +743,11 @@ export class Series<T extends Scalar = Scalar> {
744743 // monomorphic, branchless, and JIT-specialisable.
745744 // For mixed/string data fall back to the generic branch comparator.
746745 const finSlice = finBuf . subarray ( 0 , finCount ) ;
747- const fvSlice = fvals . subarray ( 0 , finCount ) ;
748746 if ( allNumeric ) {
749747 if ( ascending ) {
750- finSlice . sort ( ( a , b ) => fvSlice [ a ] ! - fvSlice [ b ] ! ) ;
748+ finSlice . sort ( ( a , b ) => fvals [ a ] ! - fvals [ b ] ! ) ;
751749 } else {
752- finSlice . sort ( ( a , b ) => fvSlice [ b ] ! - fvSlice [ a ] ! ) ;
750+ finSlice . sort ( ( a , b ) => fvals [ b ] ! - fvals [ a ] ! ) ;
753751 }
754752 } else if ( ascending ) {
755753 finSlice . sort ( ( a , b ) => {
0 commit comments