Don't use transmute to create PaintOrder values

I checked that rustc optimises the code just as well as with the transmute.

https://rust.godbolt.org/z/w6UJN4
This commit is contained in:
Anthony Ramine 2020-04-04 20:29:25 +02:00
parent 57fe27a4ef
commit 5d6c5132c1

View file

@ -146,8 +146,13 @@ impl SVGPaintOrder {
/// Get variant of `paint-order`
pub fn order_at(&self, pos: u8) -> PaintOrder {
// Safe because PaintOrder covers all possible patterns.
unsafe { std::mem::transmute((self.0 >> pos * PAINT_ORDER_SHIFT) & PAINT_ORDER_MASK) }
match (self.0 >> pos * PAINT_ORDER_SHIFT) & PAINT_ORDER_MASK {
0 => PaintOrder::Normal,
1 => PaintOrder::Fill,
2 => PaintOrder::Stroke,
3 => PaintOrder::Markers,
_ => unreachable!("this cannot happen"),
}
}
}