Skip to content

Commit f6e8d2a

Browse files
AlpAlp
authored andcommitted
chore: use typed locals instead of repeated as-casts in comparators
1 parent 730d499 commit f6e8d2a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/zql/src/ivm/memory-source.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -884,23 +884,23 @@ function makeBoundComparator(sort: Ordering) {
884884
if (bN === null) return 1;
885885
// Inline compareValues for string (most common) and number
886886
if (typeof av === 'string') {
887+
const aStr = av;
888+
const bStr = bv as string;
887889
// Inline compareStringUTF8Fast
888-
if (av === bv) return 0;
890+
if (aStr === bStr) return 0;
889891
const len =
890-
(av as string).length < (bv as string).length
891-
? (av as string).length
892-
: (bv as string).length;
892+
aStr.length < bStr.length ? aStr.length : bStr.length;
893893
for (let i = 0; i < len; i++) {
894-
const ac = (av as string).charCodeAt(i);
895-
const bc = (bv as string).charCodeAt(i);
894+
const ac = aStr.charCodeAt(i);
895+
const bc = bStr.charCodeAt(i);
896896
if (ac !== bc) {
897897
if (ac < 128 && bc < 128) return ac - bc;
898-
return compareUTF8(av as string, bv as string);
898+
return compareUTF8(aStr, bStr);
899899
}
900900
}
901-
return (av as string).length - (bv as string).length;
901+
return aStr.length - bStr.length;
902902
}
903-
if (typeof av === 'number') return (av as number) - (bv as number);
903+
if (typeof av === 'number') return av - (bv as number);
904904
// Fallback for other types (boolean, etc.)
905905
return compareValues(av as Value, bv as Value);
906906
};
@@ -948,7 +948,7 @@ function compareBounds(a: Bound, b: Bound): number {
948948
if (bN === null) {
949949
return 1;
950950
}
951-
return compareValues(a as Value, b as Value);
951+
return compareValues(aN, bN);
952952
}
953953

954954
function* generateRows(

0 commit comments

Comments
 (0)