File tree 1 file changed +16
-4
lines changed
1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -42,11 +42,13 @@ export default function suggestionList(
42
42
class LexicalDistance {
43
43
_input : string ;
44
44
_inputLowerCase : string ;
45
+ _inputArray : Array < number > ;
45
46
_rows : [ Array < number > , Array < number > , Array < number > ] ;
46
47
47
48
constructor ( input : string ) {
48
49
this . _input = input ;
49
50
this . _inputLowerCase = input . toLowerCase ( ) ;
51
+ this . _inputArray = stringToArray ( this . _inputLowerCase ) ;
50
52
51
53
this . _rows = [
52
54
new Array ( input . length + 1 ) . fill ( 0 ) ,
@@ -67,13 +69,14 @@ class LexicalDistance {
67
69
return 1 ;
68
70
}
69
71
70
- let a = optionLowerCase ;
71
- let b = this . _inputLowerCase ;
72
+ let a = stringToArray ( optionLowerCase ) ;
73
+ let b = this . _inputArray ;
74
+
72
75
if ( a . length < b . length ) {
76
+ const tmp = a ;
73
77
a = b ;
74
- b = optionLowerCase ;
78
+ b = tmp ;
75
79
}
76
-
77
80
const aLength = a . length ;
78
81
const bLength = b . length ;
79
82
@@ -123,3 +126,12 @@ class LexicalDistance {
123
126
return distance <= threshold ? distance : undefined ;
124
127
}
125
128
}
129
+
130
+ function stringToArray ( str ) {
131
+ const strLength = str . length ;
132
+ const array = new Array ( strLength ) ;
133
+ for ( let i = 0 ; i < strLength ; ++ i ) {
134
+ array [ i ] = str . charCodeAt ( i ) ;
135
+ }
136
+ return array ;
137
+ }
You can’t perform that action at this time.
0 commit comments