Skip to content

Commit

Permalink
[icons] fix(IconLoader): improve performance of isValidIconName (#6393)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Morozov <nmorozov@palantir.com>
  • Loading branch information
okaynik and Nikita Morozov committed Sep 20, 2023
1 parent e0687b5 commit d72e6de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/icons/src/iconLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { type IconName, IconNames } from "./iconNames";
import { type IconName, IconNames, IconNamesSet } from "./iconNames";
import { type IconPaths, IconSize } from "./iconTypes";
import { wrapWithTimer } from "./loaderUtils";

Expand Down Expand Up @@ -138,8 +138,7 @@ export class Icons {
* @returns true if the given string is a valid {@link IconName}
*/
public static isValidIconName(iconName: string): iconName is IconName {
const allIcons: IconName[] = Object.values(IconNames);
return allIcons.indexOf(iconName as IconName) >= 0;
return IconNamesSet.has(iconName as IconName);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/icons/src/iconNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export const IconNames = {
...IconNamesNew,
...IconNamesLegacy,
};

export const IconNamesSet = new Set(Object.values(IconNames));

1 comment on commit d72e6de

@adidahiya
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[icons] fix(IconLoader): improve performance of isValidIconName (#6393)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.