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

strconv.atoi: bug fix #18875 #18925

Merged
merged 6 commits into from Jul 22, 2023
Merged

strconv.atoi: bug fix #18875 #18925

merged 6 commits into from Jul 22, 2023

Conversation

penguindark
Copy link
Member

What is inside

}

// check for digit over base
if c >= base {
if c > basem1 || (sub_count == 0 && c > 9) {
Copy link
Member

Choose a reason for hiding this comment

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

What is 9 here? Should it not be related to _base somehow?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, basem1 stands for base - 1 that is calculated outside the loop, it is a simple optimization.
make operation inside an if is always expensive as cpu cycles.
basem1 will be stored in a register that will speed up the check in the loop.
The 9 is due the fact that if the flow arrive at that line with sub_count equal to 0 and the value is greater then 9, it is an illegal char in the sequence.
Are all optimizations in order to try to squeeze cpu cycle in the conversions.

@spytheman spytheman merged commit ba1c5de into vlang:master Jul 22, 2023
41 checks passed
@penguindark penguindark deleted the atoi_fix branch August 9, 2023 11:04
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.

None yet

2 participants