Skip to content

Commit

Permalink
fix: change useable ids to set to improve search perf (#640)
Browse files Browse the repository at this point in the history
* fix: change useable ids to set to improve search perf

* chore: appy review recommendations
  • Loading branch information
peternhale authored Feb 28, 2023
1 parent 5f236fe commit a0996a4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function getCommandIdPermutations(commandId: string): string[] {
* @param commandIds string[]
* @returns string[]
*/
export function collectUsableIds(commandIds: string[]): string[] {
export function collectUsableIds(commandIds: string[]): Set<string> {
const usuableIds: string[] = []
for (const id of commandIds) {
const parts = id.split(':')
Expand All @@ -118,5 +118,5 @@ export function collectUsableIds(commandIds: string[]): string[] {
}
}

return uniq(usuableIds).sort()
return new Set(usuableIds)
}
2 changes: 1 addition & 1 deletion src/help/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function collateSpacedCmdIDFromArgs(argv: string[], config: IConfig): string[] {
const ids = collectUsableIds(config.commandIDs)

const final: string[] = []
const idPresent = (id: string) => ids.includes(id)
const idPresent = (id: string) => ids.has(id)
const isFlag = (s: string) => s.startsWith('-')
const isArgWithValue = (s: string) => s.includes('=')
const finalizeId = (s?: string) => s ? [...final, s].join(':') : final.join(':')
Expand Down
4 changes: 2 additions & 2 deletions test/config/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ describe('util', () => {
test
.it('returns all usable command ids', async () => {
const ids = collectUsableIds(['foo:bar:baz', 'one:two:three'])
expect(ids).to.deep.equal([
expect(ids).to.deep.equal(new Set([
'foo',
'foo:bar',
'foo:bar:baz',
'one',
'one:two',
'one:two:three',
])
]))
})
})

Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -642,16 +642,11 @@
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-3.12.7.tgz#330c5d97a3500e9c903210d6e49f02964af04a0e"
integrity sha512-S6+8JAYTE1qdsc9HMVsfY7+SgSuUU/Tp6TYTmITW0PZxiyIMvol3Gy//y69Wkhs0ti4py5qgR3uZH6uz/DNzJQ==

"@types/json-schema@*":
"@types/json-schema@*", "@types/json-schema@^7.0.7":
version "7.0.11"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==

"@types/json-schema@^7.0.7":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==

"@types/lodash@*":
version "4.14.182"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2"
Expand Down

0 comments on commit a0996a4

Please sign in to comment.