Skip to content

Improve char_lit's readability and speed #36414

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

Merged
merged 2 commits into from
Sep 12, 2016
Merged

Conversation

nnethercote
Copy link
Contributor

This is my first contribution to rustc. Please let me know if I've done anything wrong. (I ran make tidy before making the pull request.)

This makes the function more concise and easier to understand.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

let idx = match lit.find('}') {
Some(idx2) => idx2,
None => panic!("lexer should have rejected a bad character escape {}", lit),
};
Copy link
Member

Choose a reason for hiding this comment

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

I find this format more verbose and adds no new information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true, but you're overlooking the speed improvement which is the motivation for the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could make this a bit less verbose while still keeping the speed improvement with unwrap_or_else:

let idx = lit.find('}').unwrap_or_else(|| {
    panic!("lexer should have rejected a bad character escape {}", lit)
});

@jseyfried
Copy link
Contributor

@nnethercote Thanks for the PR!
r=me with unwrap_or_else instead of manually unwrapping with match.

@nnethercote
Copy link
Contributor Author

@jseyfried: I'll try that. Should I modify the second patch, or make the change in an additional patch?

@jseyfried
Copy link
Contributor

@nnethercote I would just amend the second commit.

This reduces the time taken to run
`rustc -Zparse-only rustc-benchmarks/issue-32278-big-array-of-strings`
from 0.18s to 0.15s on my machine, and reduces the number of
instructions (as measured by Cachegrind) from 1.34B to 1.01B.

With the change applied, the time to fully compile that benchmark is
1.96s, so this is a 1.5% improvement.
@nnethercote
Copy link
Contributor Author

I updated the second commit. r? @jseyfried

@jseyfried
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 12, 2016

📌 Commit 826f673 has been approved by jseyfried

@bors
Copy link
Collaborator

bors commented Sep 12, 2016

⌛ Testing commit 826f673 with merge 8889703...

bors added a commit that referenced this pull request Sep 12, 2016
Improve char_lit's readability and speed

This is my first contribution to rustc. Please let me know if I've done anything wrong. (I ran `make tidy` before making the pull request.)
@bors bors merged commit 826f673 into rust-lang:master Sep 12, 2016
@nnethercote nnethercote deleted the char_lit branch October 7, 2016 05:03
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.

6 participants