Skip to content

Optimize toHex function in CommonData.cpp #16120

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

Closed
wants to merge 1 commit into from

Conversation

reallesee
Copy link

Replace incremental index updates with direct assignment when adding "0x" prefix in the toHex function. This eliminates unnecessary increment operations and makes the code more straightforward while maintaining identical functionality

Copy link

Thank you for your contribution to the Solidity compiler! A team member will follow up shortly.

If you haven't read our contributing guidelines and our review checklist before, please do it now, this makes the reviewing process and accepting your contribution smoother.

If you have any questions or need our help, feel free to post them in the PR or talk to us directly on the #solidity-dev channel on Matrix.

@clonker
Copy link
Member

clonker commented Jul 15, 2025

Thank you for your contribution! I find your reasoning at the very least debatable:

  • the entire function is built on incrementing i, so using direct assignment (albeit known) leads to less consistent code
  • if, say, the prefix(-length) changed for whatever reason, the current approach automatically accommodates for that without having to explicitly reset the index
  • there is no performance benefit, modern compilers will optimize out the increment

Since this is simply a refactor that doesn't really add anything, I'll go ahead and close this.

@clonker clonker closed this Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants