Skip to content

Commit eada2dc

Browse files
KristofferCtecosaur
authored andcommitted
Avoid needlessly creating a new Face in get calls
Instead of providing Face() as the fallback value with a get call, we can instead provide the constructor Face as the first argument, preventing it from being called needlessly.
1 parent c647af9 commit eada2dc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/faces.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ function withfaces(f, keyvals_itr)
470470
if face isa Face
471471
newfaces[name] = face
472472
elseif face isa Symbol
473-
newfaces[name] = get(FACES.current[], face, Face())
473+
newfaces[name] = get(Face, FACES.current[], face)
474474
elseif face isa Vector{Symbol}
475475
newfaces[name] = Face(inherit=face)
476476
elseif haskey(newfaces, name)
@@ -517,7 +517,7 @@ function Base.merge(a::Face, b::Face)
517517
b_noinherit = Face(
518518
b.font, b.height, b.weight, b.slant, b.foreground, b.background,
519519
b.underline, b.strikethrough, b.inverse, Symbol[])
520-
b_inheritance = map(fname -> get(FACES.current[], fname, Face()), Iterators.reverse(b.inherit))
520+
b_inheritance = map(fname -> get(Face, FACES.current[], fname), Iterators.reverse(b.inherit))
521521
b_resolved = merge(foldl(merge, b_inheritance), b_noinherit)
522522
merge(a, b_resolved)
523523
end
@@ -529,7 +529,7 @@ Base.merge(a::Face, b::Face, others::Face...) = merge(merge(a, b), others...)
529529

530530
# Putting these inside `getface` causes the julia compiler to box it
531531
_mergedface(face::Face) = face
532-
_mergedface(face::Symbol) = get(FACES.current[], face, Face())
532+
_mergedface(face::Symbol) = get(Face, FACES.current[], face)
533533
_mergedface(faces::Vector) = mapfoldl(_mergedface, merge, Iterators.reverse(faces))
534534

535535
"""
@@ -558,7 +558,7 @@ function getface(annotations::Vector{Pair{Symbol, Any}})
558558
end
559559

560560
getface(face::Face) = merge(FACES.current[][:default], merge(Face(), face))
561-
getface(face::Symbol) = getface(get(FACES.current[], face, Face()))
561+
getface(face::Symbol) = getface(get(Face, FACES.current[], face))
562562

563563
"""
564564
getface()

0 commit comments

Comments
 (0)