Skip to content

Commit fe91c2b

Browse files
author
Aditya Thakral
committed
Remove double find
1 parent ca0450b commit fe91c2b

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/vs/base/common/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ export function isUndefined(obj: any): obj is undefined {
6464
return (typeof obj === 'undefined');
6565
}
6666

67+
/**
68+
* @returns whether the provided parameter is defined.
69+
*/
70+
export function isDefined<T>(arg: T | null | undefined): arg is T {
71+
return !isUndefinedOrNull(arg);
72+
}
73+
6774
/**
6875
* @returns whether the provided parameter is undefined or null.
6976
*/

src/vs/workbench/contrib/preferences/browser/settingsTree.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { Disposable, DisposableStore, dispose } from 'vs/base/common/lifecycle';
3030
import { isIOS } from 'vs/base/common/platform';
3131
import { ISpliceable } from 'vs/base/common/sequence';
3232
import { escapeRegExpCharacters, startsWith } from 'vs/base/common/strings';
33-
import { isArray } from 'vs/base/common/types';
33+
import { isArray, isDefined } from 'vs/base/common/types';
3434
import { localize } from 'vs/nls';
3535
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
3636
import { ICommandService } from 'vs/platform/commands/common/commands';
@@ -131,11 +131,13 @@ function getObjectDisplayValue(element: SettingsTreeSettingElement): IObjectData
131131

132132
const keysWithSchema = Object.keys(data)
133133
.filter(key => !!data[key] && !(key in (element.setting.objectProperties ?? {})))
134-
.filter(key => patternsAndSchemas.find(({ pattern }) => pattern.test(key)))
135134
.map(key => {
136-
const { schema } = patternsAndSchemas.find(({ pattern }) => pattern.test(key))!;
137-
return { key, schema };
138-
});
135+
const patternAndSchema = patternsAndSchemas.find(({ pattern }) => pattern.test(key));
136+
return patternAndSchema
137+
? { key, schema: patternAndSchema.schema }
138+
: undefined;
139+
})
140+
.filter(isDefined);
139141

140142
items = items.concat(keysWithSchema.map(({ key, schema }) => {
141143
const valueEnumOptions = getEnumOptionsFromSchema(schema);

0 commit comments

Comments
 (0)