Skip to content

Commit 8d1d4a3

Browse files
Copilotmrjf
andauthored
fix: correct numeric fast-path indexing in Series.sortValues
Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/ecf1056a-d429-45df-964d-d721723e5413 Co-authored-by: mrjf <[email protected]>
1 parent b07ee72 commit 8d1d4a3

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/core/series.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)