Skip to content

Commit 20f5a4b

Browse files
committed
Remove redundant trim/toLowerCase in scoreQueryMatch
All callers already pass pre-normalized (trimmed and lowercased) inputs, so the internal .trim().toLowerCase() calls were redundant O(n) string operations allocating unnecessary copies on every candidate per keystroke. Replace with a destructured read and a JSDoc contract stating that inputs must be pre-normalized.
1 parent b0488e2 commit 20f5a4b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/shared/src/searchRanking.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ function findBoundaryMatchIndex(
7777
return bestIndex;
7878
}
7979

80+
/**
81+
* Scores how well `value` matches `query` using tiered match strategies.
82+
*
83+
* **Expects pre-normalized inputs**: both `value` and `query` must already be
84+
* trimmed and lowercased (e.g. via {@link normalizeSearchQuery}).
85+
*/
8086
export function scoreQueryMatch(input: {
8187
value: string;
8288
query: string;
@@ -87,8 +93,7 @@ export function scoreQueryMatch(input: {
8793
fuzzyBase?: number;
8894
boundaryMarkers?: readonly string[];
8995
}): number | null {
90-
const value = input.value.trim().toLowerCase();
91-
const query = input.query.trim().toLowerCase();
96+
const { value, query } = input;
9297

9398
if (!value || !query) {
9499
return null;

0 commit comments

Comments
 (0)