From 895a15b3218f820af6af714e1dde9f086deba0ca Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sun, 11 Aug 2019 19:29:09 +0100 Subject: Add syntax highlighting cache --- scene/gui/text_edit.cpp | 21 ++++++++++++++++++++- scene/gui/text_edit.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'scene/gui') diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f137b2618b..f3a4ca9e83 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -573,6 +573,7 @@ void TextEdit::_notification(int p_what) { _update_caches(); _update_wrap_at(); + syntax_highlighting_cache.clear(); } break; case MainLoop::NOTIFICATION_WM_FOCUS_IN: { window_has_focus = true; @@ -3714,6 +3715,15 @@ void TextEdit::_line_edited_from(int p_line) { for (int i = p_line; i < cache_size; i++) { color_region_cache.erase(i); } + + if (syntax_highlighting_cache.size() > 0) { + cache_size = syntax_highlighting_cache.back()->key(); + for (int i = p_line - 1; i < cache_size; i++) { + if (syntax_highlighting_cache.has(i)) { + syntax_highlighting_cache.erase(i); + } + } + } } int TextEdit::get_char_count() { @@ -4569,6 +4579,7 @@ void TextEdit::_set_syntax_highlighting(SyntaxHighlighter *p_syntax_highlighter) syntax_highlighter->set_text_editor(this); syntax_highlighter->_update_cache(); } + syntax_highlighting_cache.clear(); update(); } @@ -4635,6 +4646,7 @@ void TextEdit::clear_colors() { keywords.clear(); color_regions.clear(); color_region_cache.clear(); + syntax_highlighting_cache.clear(); text.clear_width_cache(); } @@ -6707,8 +6719,14 @@ TextEdit::~TextEdit() { /////////////////////////////////////////////////////////////////////////////// Map TextEdit::_get_line_syntax_highlighting(int p_line) { + if (syntax_highlighting_cache.has(p_line)) { + return syntax_highlighting_cache[p_line]; + } + if (syntax_highlighter != NULL) { - return syntax_highlighter->_get_line_syntax_highlighting(p_line); + Map color_map = syntax_highlighter->_get_line_syntax_highlighting(p_line); + syntax_highlighting_cache[p_line] = color_map; + return color_map; } Map color_map; @@ -6890,6 +6908,7 @@ Map TextEdit::_get_line_syntax_highlighting(int } } + syntax_highlighting_cache[p_line] = color_map; return color_map; } diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b47dac0902..a52e6a72ba 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -214,6 +214,7 @@ private: } cache; Map color_region_cache; + Map > syntax_highlighting_cache; struct TextOperation { -- cgit v1.2.3