Skip to content

Commit 201d732

Browse files
author
Brian Vaughn
committed
Replaced substring() with charAt() + concat for index strategys for a slight perf boost
1 parent 599d283 commit 201d732

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

source/IndexStrategy/AllSubstringsIndexStrategy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ export class AllSubstringsIndexStrategy implements IIndexStrategy {
1212
*/
1313
expandToken(token : string) : Array<string> {
1414
var expandedTokens = [];
15+
var string;
1516

1617
for (var i = 0, length = token.length; i < length; ++i) {
18+
string = '';
19+
1720
for (var j = i; j < length; ++j) {
18-
expandedTokens.push(token.substring(i, j + 1));
21+
string += token.charAt(j);
22+
expandedTokens.push(string);
1923
}
2024
}
2125

source/IndexStrategy/PrefixIndexStrategy.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ export class PrefixIndexStrategy implements IIndexStrategy {
1212
*/
1313
expandToken(token : string) : Array<string> {
1414
var expandedTokens = [];
15+
var string = '';
1516

1617
for (var i = 0, length = token.length; i < length; ++i) {
17-
expandedTokens.push(token.substring(0, i + 1));
18+
string += token.charAt(i);
19+
expandedTokens.push(string);
1820
}
1921

2022
return expandedTokens;

0 commit comments

Comments
 (0)