Skip to content

Commit cde6dd3

Browse files
committed
Remove instances of broadcasting
While broadcasting is convenient syntax, it's tough on the compiler, and so likely not worth it in library code like this. While the face equality method was initially rewritten to use a for loop, it was incredibly type-unstable and so is better written out in full.
1 parent 03b823b commit cde6dd3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/faces.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,18 @@ function Face(; font::Union{Nothing, String} = nothing,
170170
else inherit end)
171171
end
172172

173-
Base.:(==)(a::Face, b::Face) =
174-
getfield.(Ref(a), fieldnames(Face)) ==
175-
getfield.(Ref(b), fieldnames(Face))
173+
function Base.:(==)(a::Face, b::Face)
174+
a.font == b.font &&
175+
a.height === b.height &&
176+
a.weight == b.weight &&
177+
a.slant == b.slant &&
178+
a.foreground == b.foreground &&
179+
a.background == b.background &&
180+
a.underline == b.underline &&
181+
a.strikethrough == b.strikethrough &&
182+
a.inverse == b.inverse &&
183+
a.inherit == b.inherit
184+
end
176185

177186
Base.hash(f::Face, h::UInt) =
178187
mapfoldr(Base.Fix1(getfield, f), hash, fieldnames(Face), init=hash(Face, h))
@@ -714,7 +723,7 @@ function Base.convert(::Type{Face}, spec::Dict{String,Any})
714723
elseif spec["inherit"] isa String
715724
[Symbol(spec["inherit"]::String)]
716725
elseif spec["inherit"] isa Vector{String}
717-
Symbol.(spec["inherit"]::Vector{String})
726+
[Symbol(name) for name in spec["inherit"]::Vector{String}]
718727
else
719728
Symbol[]
720729
end)

src/legacy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ legacy_color(color::Symbol) =
9393
end
9494

9595
function legacy_color(color::String)
96-
namedcolours = String.(NAMED_COLORS)
96+
namedcolours = map(String, NAMED_COLORS)
9797
if color in namedcolours
9898
legacy_color(Symbol(color))
9999
elseif 0 <= (color256 = something(tryparse(Int, color), -1)) <= 255

0 commit comments

Comments
 (0)