Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change useable ids to set to improve search perf #640

Merged
merged 2 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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