Bug 1630676 - Don't use transmute to create PaintOrder values. r=emilio

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 committed by Emilio Cobos Álvarez
parent 40593d91fb
commit 26b6ee1d3a

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"),
}
}
}