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

optimize CharStream class in liblangutil #15095

Closed
wants to merge 1 commit into from

Conversation

moroii69
Copy link

summary:

  • replaced unnecessary copying of strings with string views and move semantics where appropriate.
  • used std::min and std::max instead of ternary operators for readability.
  • avoided redundant string operations such as substr and find, especially within loops.
  • ensured const correctness by marking appropriate member functions as const.

details:

  • advanceAndGet: refactored to return early when reaching the end of input and simplified return statement.
  • rollback: no changes, but added comments for clarity.
  • setPosition: added assertion to ensure the position is within bounds of the source.
  • lineAtPosition: simplified logic for finding the line and end position.
  • translatePositionToLineColumn: simplified logic for calculating line number and line start position.
  • text: added additional conditions to check for valid location and source name.
  • singleLineSnippet: no changes, but added comments for clarity.
  • translateLineColumnToPosition: simplified logic for finding the position corresponding to a given line and column.

test plan:

  • ran existing unit tests to ensure functionality is preserved. Unit Testing in C++
  • compiled and tested the code with sample inputs to verify optimizations.

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.

@nikola-matic
Copy link
Collaborator

Hi @moroii69. Unfortunately, I'll be closing the PR as it doesn't actually optimize much, and we're generally not fans of using ternary expressions so frequently as it detracts from the code readability. In addition, this isn't really a bottleneck that would require sacrificing readability for no actual performance gain.

For future reference however, note that we use tabs instead of spaces, which is why the check_style step of the build failed. Also, the build fails on all of our unix-like (Linux, MacOS) platforms, i.e. it does not compile.

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.

None yet

3 participants