Skip to content

Commit 9b9cf71

Browse files
KristofferCtecosaur
authored andcommitted
Use branches when choosing how to merge face attrs
While ifelse looked like a reasonable choice, it turns out that the performance (allocations in particular) is improved by creating a branch. We go from 2 allocations to 0 when merging faces, which very much adds up over time.
1 parent eada2dc commit 9b9cf71

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/faces.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,20 @@ function Base.merge(a::Face, b::Face)
499499
# to narrow the types in e.g. `aheight * bheight`
500500
aheight = a.height
501501
bheight = b.height
502-
Face(ifelse(isnothing(b.font), a.font, b.font),
503-
if isnothing(bheight) aheight
504-
elseif isnothing(aheight) bheight
505-
elseif bheight isa Int bheight
506-
elseif aheight isa Int round(Int, aheight * bheight)
507-
else aheight * bheight end,
508-
ifelse(isnothing(b.weight), a.weight, b.weight),
509-
ifelse(isnothing(b.slant), a.slant, b.slant),
510-
ifelse(isnothing(b.foreground), a.foreground, b.foreground),
511-
ifelse(isnothing(b.background), a.background, b.background),
512-
ifelse(isnothing(b.underline), a.underline, b.underline),
513-
ifelse(isnothing(b.strikethrough), a.strikethrough, b.strikethrough),
514-
ifelse(isnothing(b.inverse), a.inverse, b.inverse),
502+
abheight = if isnothing(bheight) aheight
503+
elseif isnothing(aheight) bheight
504+
elseif bheight isa Int bheight
505+
elseif aheight isa Int round(Int, aheight * bheight)
506+
else aheight * bheight end
507+
Face(if isnothing(b.font) a.font else b.font end,
508+
abheight,
509+
if isnothing(b.weight) a.weight else b.weight end,
510+
if isnothing(b.slant) a.slant else b.slant end,
511+
if isnothing(b.foreground) a.foreground else b.foreground end,
512+
if isnothing(b.background) a.background else b.background end,
513+
if isnothing(b.underline) a.underline else b.underline end,
514+
if isnothing(b.strikethrough) a.strikethrough else b.strikethrough end,
515+
if isnothing(b.inverse) a.inverse else b.inverse end,
515516
a.inherit)
516517
else
517518
b_noinherit = Face(

0 commit comments

Comments
 (0)