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

Iterator specialization for EscapeDefaults #30624

Merged
merged 2 commits into from
Jan 16, 2016
Merged

Conversation

ticki
Copy link
Contributor

@ticki ticki commented Dec 29, 2015

Part of #30520. Completes #24214

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (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.

EscapeDefaultState::Unicode(ref mut i) => return i.nth(n),
};

let start = if let Some(x) = self.get_offset() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be convenient to fold this into the previous match?
I did something similar here: ranma42@0cdfa6d

@ranma42
Copy link
Contributor

ranma42 commented Dec 29, 2015

Does this commit complete the tasks listed in #24214 ? AFAICT EscapeUnicode is still missing. I mentioned on the issue that have the branch https://github.com/ranma42/rust/tree/escape-iters for both EscapeDefault and EscapeUnicode, but there seemed to be no interest in merging it.

@ticki
Copy link
Contributor Author

ticki commented Dec 30, 2015

@ranma42 Interesting. It's true that it doesn't fix the EscapeUnicode. Have you tried to send a pull request?

@ranma42
Copy link
Contributor

ranma42 commented Dec 30, 2015

I will send one soon. I had some unresolved questions, though, about how to handle code duplication and whether the methods should be #[inline]. I guess I will choose and fix as per suggestions on the PR.

@ticki
Copy link
Contributor Author

ticki commented Dec 30, 2015

@ranma42 I don't think they should be so. They're not simple enough for inlining to be worth it.

@ticki
Copy link
Contributor Author

ticki commented Jan 1, 2016

r? @aturon

@rust-highfive rust-highfive assigned aturon and unassigned brson Jan 1, 2016
@ranma42
Copy link
Contributor

ranma42 commented Jan 2, 2016

I believe that the test should be moved to src/libcoretest/char.rs (I tested my implementations using your test, too, but I was unable to get its results as part of "make check" until I did that ;) ).

} else {
return None;
};
let idx = start + n;
Copy link
Contributor

Choose a reason for hiding this comment

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

This sum can overflow if when n = usize::MAX and start = 1 (i.e. self.state is Char(_)).

@ticki
Copy link
Contributor Author

ticki commented Jan 12, 2016

@alexcrichton I have now fixed the comments you gave.

EscapeDefaultState::Unicode(ref mut i) => return i.nth(n),
};

let start = if let Some(x) = self.get_offset() {
Copy link
Member

Choose a reason for hiding this comment

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

This method may not be necessary as it can just be folded into the match above

@ticki
Copy link
Contributor Author

ticki commented Jan 15, 2016

@alexcrichton I updated it to reflect your points.

@ranma42
Copy link
Contributor

ranma42 commented Jan 15, 2016

@alexcrichton I have a branch which specialises EscapeDefaults and EscapeUnicode and uses the offset/index trick in both; the symmetry might make it more clear why it is convenient. I plan to make the PR after this is landed (to reuse some parts of this, including the new test).

@alexcrichton
Copy link
Member

Ok, we can perhaps try to unify once they both exist, but at least for now this seems more understandable to me at least.

@ticki, can you also squash the commits together? Other than that looks good to me, thanks!

@ticki
Copy link
Contributor Author

ticki commented Jan 16, 2016

@alexcrichton Yep. Will do.

@ticki
Copy link
Contributor Author

ticki commented Jan 16, 2016

Squash done!

@alexcrichton
Copy link
Member

Looks like some other snuck in by accident?

@ticki
Copy link
Contributor Author

ticki commented Jan 16, 2016

Damn. Will fix.

ticki added 2 commits January 16, 2016 09:12
…e tests to libcoretest

Remove unused import

Fold nth() method into the match expr
@ticki
Copy link
Contributor Author

ticki commented Jan 16, 2016

@alexcrichton Fixed.

@alexcrichton
Copy link
Member

@bors: r+ d026977

@bors
Copy link
Contributor

bors commented Jan 16, 2016

⌛ Testing commit d026977 with merge 1f516dc...

bors added a commit that referenced this pull request Jan 16, 2016
@bors bors merged commit d026977 into rust-lang:master Jan 16, 2016
@ticki ticki deleted the specialization branch January 17, 2016 12:53
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.

7 participants