Skip to content

Commit c647af9

Browse files
KristofferCtecosaur
authored andcommitted
Avoid boxing mergedface by making it toplevel
Running a benchmark on a large, heavily annotated string we see a 25% reduction in runtime (12.9ms -> 9.5ms) and a 29% reduction in allocations (408k -> 290k).
1 parent a117008 commit c647af9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/faces.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ Base.merge(a::Face, b::Face, others::Face...) = merge(merge(a, b), others...)
527527

528528
## Getting the combined face from a set of properties ##
529529

530+
# Putting these inside `getface` causes the julia compiler to box it
531+
_mergedface(face::Face) = face
532+
_mergedface(face::Symbol) = get(FACES.current[], face, Face())
533+
_mergedface(faces::Vector) = mapfoldl(_mergedface, merge, Iterators.reverse(faces))
534+
530535
"""
531536
getface(faces)
532537
@@ -535,10 +540,7 @@ Obtain the final merged face from `faces`, an iterator of
535540
"""
536541
function getface(faces)
537542
isempty(faces) && return FACES.current[][:default]
538-
mergedface(face::Face) = face
539-
mergedface(face::Symbol) = get(FACES.current[], face, Face())
540-
mergedface(faces::Vector) = mapfoldl(mergedface, merge, Iterators.reverse(faces))
541-
combined = mapfoldl(mergedface, merge, faces)::Face
543+
combined = mapfoldl(_mergedface, merge, faces)::Face
542544
if !isempty(combined.inherit)
543545
combined = merge(Face(), combined)
544546
end

0 commit comments

Comments
 (0)