Skip to content

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