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

[core] Replace more indexOf with includes #43694

Merged
merged 2 commits into from
Sep 12, 2024
Merged

[core] Replace more indexOf with includes #43694

merged 2 commits into from
Sep 12, 2024

Conversation

Juneezee
Copy link
Contributor

This PR is a follow-up of #42883 (review) and #42883 (review).

/cc @aarongarciah @Janpot

@zannager zannager added the core Infrastructure work going on behind the scenes label Sep 11, 2024
@@ -9,7 +9,7 @@ function omit(input, fields) {
const output = {};

Object.keys(input).forEach((prop) => {
if (fields.indexOf(prop) === -1) {
if (!fields.includes(prop)) {
Copy link
Member

@Janpot Janpot Sep 12, 2024

Choose a reason for hiding this comment

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

Just for demonstration purposes, but this is one of those hidden O(nm) complexities that can be reduced down to O(n)+O(m):

function omit(input, fields) {
  const output = {};
  const fieldSet = new Set(fields)
  Object.keys(input).forEach((prop) => {
    if (!fieldSet.has(prop)) {
      output[prop] = input[prop];
    }
  });
  return output;
}

Not to be changed unless proven to be a real performance improvement though, it adds an extra allocation. This comment is just for information only.

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Looks good

Copy link
Member

@aarongarciah aarongarciah left a comment

Choose a reason for hiding this comment

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

I went through all the changes and they look correct, thanks!

This commit is a follow-up of
#42883 (review).

Signed-off-by: Eng Zer Jun <[email protected]>
@mui-bot
Copy link

mui-bot commented Sep 12, 2024

Netlify deploy preview

https://deploy-preview-43694--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against d6ee1e6

@@ -496,7 +496,7 @@ const attachPropsTable = (

const requiredProp =
prop.required ||
/\.isRequired/.test(prop.type.raw) ||
prop.type.raw.includes('.isRequired') ||
Copy link
Member

@aarongarciah aarongarciah Sep 12, 2024

Choose a reason for hiding this comment

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

This line is failing when raw is not a string. I pushed this fix:

-        prop.type.raw.includes('.isRequired') ||
+        prop.type.raw?.includes('.isRequired') ||

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants