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

refactor: parse int as number or big int #804

Conversation

NguyenTuanCanh
Copy link
Contributor

Development related changes

1.Use Number.isInteger to check if the input can be parsed as an integer, and if not, we parse it as a float.
2.Use Number(x) to convert the string to a number for checking integer type.
3.Split the condition and result into separate lines for improved readability.
4.Use Number.isSafeInteger to check if the parsed integer is within the safe integer range.
4.If it's a safe integer, we return it as a regular number; otherwise, we return it as a BigInt.

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

Copy link

netlify bot commented Nov 2, 2023

Deploy Preview for starknetjs canceled.

Name Link
🔨 Latest commit 49739af
🔍 Latest deploy log https://app.netlify.com/sites/starknetjs/deploys/654368a4c237bb0008e8d006

Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

Thank you for a nice try.

  • I do not see significant gain between regex and number solution, other than using the lib method, what can be removed by doing, or creating local isInteger(str: String)
/^-?[0-9]+$/.test(x)

https://www.measurethat.net/Benchmarks/Show/28243/0/compare-number-vs-regex-test

  • Regarding readability more compact method is preferred as more convenient to read.

Please provide a convenient argument for the change
If you would like to contribute please take some of the open Issues.

@penovicp
Copy link
Collaborator

penovicp commented Nov 5, 2023

Also didn't notice a performance change with a benchmark that uses the different approaches within the lossless-json parser override method.

@penovicp penovicp closed this Nov 5, 2023
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.

3 participants