Skip to content

Commit 4d04102

Browse files
KristofferCtecosaur
authored andcommitted
Optimise creation of a SimpleColor from a UInt32
Instead of creating a temporary array that we reinterpret into another temporary array, we can just pick out the bytes we want from within the UInt32.
1 parent 6d3f44d commit 4d04102

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/faces.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ struct SimpleColor
2525
end
2626

2727
SimpleColor(r::Integer, g::Integer, b::Integer) = SimpleColor((; r=UInt8(r), g=UInt8(g), b=UInt8(b)))
28-
SimpleColor(rgb::UInt32) = SimpleColor(reverse(reinterpret(UInt8, [rgb]))[2:end]...)
28+
29+
function SimpleColor(rgb::UInt32)
30+
_, g, b, r = reinterpret(NTuple{4, UInt8}, rgb)
31+
SimpleColor(r, g, b)
32+
end
2933

3034
Base.convert(::Type{SimpleColor}, (; r, g, b)::RGBTuple) = SimpleColor((; r, g, b))
3135
Base.convert(::Type{SimpleColor}, namedcolor::Symbol) = SimpleColor(namedcolor)

0 commit comments

Comments
 (0)