[geany/geany] 935651: Perform typename re-colourisation only when typename list changes

Jiří Techet git-noreply at xxxxx
Tue May 17 20:58:47 UTC 2016

Branch:      refs/heads/master
Author:      Jiří Techet <techet at gmail.com>
Committer:   Jiří Techet <techet at gmail.com>
Date:        Tue, 17 May 2016 20:58:47 UTC
Commit:      9356514e457c34da3169b6531862b538e1a961bb

Log Message:
Perform typename re-colourisation only when typename list changes

To detect the change of typename list since the last time the colourisation
happened, we could store the complete typename string used during the
last colourization and compare it with the current string. For lots of
typenames this might be quite a huge string stored for every opened tab
(well, it's also stored in Scintilla already for every document but better
not to have it twice). Instead, we can store an uint hash of the string.
We could also use a better hash function with longer hash value but
uint size should be enough for this case (and in the case of a collision
nothing terrible happens).

Modified Paths:

Modified: src/document.c
11 lines changed, 9 insertions(+), 2 deletions(-)
@@ -2750,10 +2750,17 @@ void document_highlight_tags(GeanyDocument *doc)
 	keywords_str = symbols_find_typenames_as_string(doc->file_type->lang, FALSE);
 	if (keywords_str)
+		guint hash;
 		keywords = g_string_free(keywords_str, FALSE);
-		sci_set_keywords(doc->editor->sci, keyword_idx, keywords);
+		hash = g_str_hash(keywords);
+		if (hash != doc->priv->keyword_hash)
+		{
+			sci_set_keywords(doc->editor->sci, keyword_idx, keywords);
+			queue_colourise(doc); /* force re-highlighting the entire document */
+			doc->priv->keyword_hash = hash;
+		}
-		queue_colourise(doc); /* force re-highlighting the entire document */

Modified: src/documentprivate.h
1 lines changed, 1 insertions(+), 0 deletions(-)
@@ -90,6 +90,7 @@ typedef struct GeanyDocumentPrivate
 	/* Used so Undo/Redo works for encoding changes. */
 	FileEncoding	 saved_encoding;
 	gboolean		 colourise_needed;	/* use document.c:queue_colourise() instead */
+	guint			 keyword_hash;	/* hash of keyword string used for typename colourisation */
 	gint			 line_count;		/* Number of lines in the document. */
 	gint			 symbol_list_sort_mode;
 	/* indicates whether a file is on a remote filesystem, works only with GIO/GVfs */

This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).

More information about the Commits mailing list