From 12ef466f3a5dc97f9358e35eb4cfa5e16458afa9 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 24 Sep 2015 13:55:06 +0100 Subject: [PATCH] Avoid redundant calls to get_face in highlight_selections --- src/highlighters.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 8dd420e1..052ff657 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -822,7 +822,13 @@ void highlight_selections(const Context& context, HighlightFlags flags, DisplayB { if (flags != HighlightFlags::Highlight) return; + const auto& buffer = context.buffer(); + const Face primary_face = get_face("PrimarySelection"); + const Face secondary_face = get_face("SecondarySelection"); + const Face primary_cursor_face = get_face("PrimaryCursor"); + const Face secondary_cursor_face = get_face("SecondaryCursor"); + for (size_t i = 0; i < context.selections().size(); ++i) { auto& sel = context.selections()[i]; @@ -831,17 +837,15 @@ void highlight_selections(const Context& context, HighlightFlags flags, DisplayB ByteCoord end = forward ? (ByteCoord)sel.cursor() : buffer.char_next(sel.anchor()); const bool primary = (i == context.selections().main_index()); - Face sel_face = get_face(primary ? "PrimarySelection" : "SecondarySelection"); highlight_range(display_buffer, begin, end, false, - apply_face(sel_face)); + apply_face(primary ? primary_face : secondary_face)); } for (size_t i = 0; i < context.selections().size(); ++i) { auto& sel = context.selections()[i]; const bool primary = (i == context.selections().main_index()); - Face cur_face = get_face(primary ? "PrimaryCursor" : "SecondaryCursor"); highlight_range(display_buffer, sel.cursor(), buffer.char_next(sel.cursor()), false, - apply_face(cur_face)); + apply_face(primary ? primary_cursor_face : secondary_cursor_face)); } }