Skip to content

Commit e545162

Browse files
committed
suggestionList: micro-optiomisations
1 parent 21e544d commit e545162

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/jsutils/suggestionList.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default function suggestionList(
1313

1414
const inputThreshold = input.length / 2;
1515
for (const option of options) {
16-
const threshold = Math.max(inputThreshold, option.length / 2, 1);
16+
const threshold = Math.max(inputThreshold, option.length / 2, 1) | 0;
1717
const distance = lexicalDistance.measure(option, threshold);
1818
if (distance !== undefined) {
1919
optionsByDistance[option] = distance;
@@ -68,13 +68,17 @@ class LexicalDistance {
6868
return 1;
6969
}
7070

71-
const a = optionLowerCase;
72-
const b = this._inputLowerCase;
71+
let a = optionLowerCase;
72+
let b = this._inputLowerCase;
73+
if (a.length < b.length) {
74+
a = b;
75+
b = optionLowerCase;
76+
}
7377

7478
const aLength = a.length;
7579
const bLength = b.length;
7680

77-
if (Math.abs(aLength - bLength) > threshold) {
81+
if (aLength - bLength > threshold) {
7882
return undefined;
7983
}
8084

0 commit comments

Comments
 (0)