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

Avoid duplicate toCode calls in multiple Char.is... functions #1146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jfmengels
Copy link
Contributor

This reduces the number of calls to toCode char. For instance, in the isAlphaNum function, the char argument would be converted to a char up to 3 times (once in isLower, isUpper and isDigit).

This makes it so that the conversion is done at most once, improving performance of the functions.

@lue-bird discovered this as an optimization for parsers (as part of stil4m/elm-syntax#237), where the Char.isAlphaNum function is used to identify variables.


Functions like isUpper now make a function call to delegate to their dedicated helper. I don't know if it matters much (I assume a JIT compiler will optimize this) and we could duplicate the comparison logic in both isUpper and isUpperCode to avoid that, but I figured reducing duplication and therefore potential errors to be a reasonable default. I'mm happy to change this.

This reduces the number of calls to `toCode char`. For instance, in the
isAlphaNum function, the char argument would be converted to a char up
to 3 times (once in isLower, isUpper and isDigit).
This makes it so that the conversion is done at most once, improving
performance of the functions.
Copy link

Thanks for suggesting these code changes. To set expectations:

  • Pull requests are reviewed in batches, so it can take some time to get a response.
  • Smaller pull requests are easier to review. To fix nine typos, nine specific issues will always go faster than one big one. Learn why here.
  • Reviewers may not know as much as you about certain situations, so add links to supporting evidence for important claims, especially regarding standards for CSS, HTTP, URI, etc.

Finally, please be patient with the core team. They are trying their best with limited resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant