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

Simplify Alignment::pretty #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Simplify Alignment::pretty #17

wants to merge 2 commits into from

Conversation

TianyiShi2001
Copy link
Member

This should be faster and cleaner.

Comment on lines +202 to +211
// SAFETY: validity checked before creating an Alignment
unsafe {
x_pretty.push_str(std::str::from_utf8_unchecked(&x[..self.xstart]));
}
for k in y.iter().take(self.ystart) {
y_pretty.push_str(&format!("{}", String::from_utf8_lossy(&[*k])));
inb_pretty.push(' ');
x_pretty.push(' ')
y_pretty.push_str(&" ".repeat(self.xstart));
unsafe {
y_pretty.push_str(std::str::from_utf8_unchecked(&y[..self.ystart]));
}
x_pretty.push_str(&" ".repeat(self.ystart));
inb_pretty.push_str(&" ".repeat(self.xstart + self.ystart));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not too fond of unnecessary unsafes, and I doubt performance is crucial for pretty printing alignments (disregarding the fact that this might not even be faster).
However, since TextSlice is just an alias for &'a [u8] and u8 as char though confusing, usually works as expected, x_pretty.push_str(...) may be replaced by &x[..self.xstart].for_each(|x| x_pretty.push(x as char)) or so.

@dlaehnemann
Copy link
Member

Just a quick ping to see, if there are any plans on following up on this? If not, we might close this whenever we come back to sifting through the pull requests over here.

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.

3 participants