[geany/geany] e027e2: Merge pull request #2747 from geany/startup-speed
Colomban Wendling
git-noreply at xxxxx
Sun Feb 7 21:37:55 UTC 2021
Branch: refs/heads/master
Author: Colomban Wendling <ban at herbesfolles.org>
Committer: Colomban Wendling <ban at herbesfolles.org>
Date: Sun, 07 Feb 2021 21:37:55 UTC
Commit: e027e240c279040c2f6bc9ea0aaccc2cac2ca94e
https://github.com/geany/geany/commit/e027e240c279040c2f6bc9ea0aaccc2cac2ca94e
Log Message:
-----------
Merge pull request #2747 from geany/startup-speed
Fix startup speed
Modified Paths:
--------------
src/editor.c
src/sciwrappers.c
Modified: src/editor.c
18 lines changed, 13 insertions(+), 5 deletions(-)
===================================================================
@@ -4597,25 +4597,34 @@ void editor_ensure_final_newline(GeanyEditor *editor)
}
-void editor_set_font(GeanyEditor *editor, const gchar *font)
+/* Similar to editor_set_font() but *only* sets the font, and doesn't take care
+ * of updating properties that might depend on the font */
+static void set_font(ScintillaObject *sci, const gchar *font)
{
gint style;
gchar *font_name;
PangoFontDescription *pfd;
gdouble size;
- g_return_if_fail(editor);
+ g_return_if_fail(sci);
pfd = pango_font_description_from_string(font);
size = pango_font_description_get_size(pfd) / (gdouble) PANGO_SCALE;
font_name = g_strdup_printf("!%s", pango_font_description_get_family(pfd));
pango_font_description_free(pfd);
for (style = 0; style <= STYLE_MAX; style++)
- sci_set_font_fractional(editor->sci, style, font_name, size);
+ sci_set_font_fractional(sci, style, font_name, size);
g_free(font_name);
+}
+
+void editor_set_font(GeanyEditor *editor, const gchar *font)
+{
+ g_return_if_fail(editor);
+
+ set_font(editor->sci, font);
update_margins(editor->sci);
/* zoom to 100% to prevent confusion */
sci_zoom_off(editor->sci);
@@ -4926,7 +4935,6 @@ static ScintillaObject *create_new_sci(GeanyEditor *editor)
setup_sci_keys(sci);
- sci_set_symbol_margin(sci, editor_prefs.show_markers_margin);
sci_set_lines_wrapped(sci, editor->line_wrapping);
sci_set_caret_policy_x(sci, CARET_JUMPS | CARET_EVEN, 0);
/* Y policy is set in editor_apply_update_prefs() */
@@ -5000,7 +5008,7 @@ ScintillaObject *editor_create_widget(GeanyEditor *editor)
editor->sci = sci;
editor_set_indent(editor, iprefs->type, iprefs->width);
- editor_set_font(editor, interface_prefs.editor_font);
+ set_font(editor->sci, interface_prefs.editor_font);
editor_apply_update_prefs(editor);
/* if editor already had a widget, restore it */
Modified: src/sciwrappers.c
39 lines changed, 38 insertions(+), 1 deletions(-)
===================================================================
@@ -144,10 +144,47 @@ void sci_set_mark_long_lines(ScintillaObject *sci, gint type, gint column, const
}
+/* Calls SCI_TEXTHEIGHT but tries very hard to cache the result as it's a very
+ * expensive operation */
+static gint sci_text_height_cached(ScintillaObject *sci)
+{
+ struct height_spec {
+ gchar *font;
+ gint size;
+ gint zoom;
+ gint extra;
+ };
+ static struct height_spec cache = {0};
+ static gint cache_value = 0;
+ struct height_spec current;
+
+ current.font = sci_get_string(sci, SCI_STYLEGETFONT, 0);
+ current.size = SSM(sci, SCI_STYLEGETSIZEFRACTIONAL, 0, 0);
+ current.zoom = SSM(sci, SCI_GETZOOM, 0, 0);
+ current.extra = SSM(sci, SCI_GETEXTRAASCENT, 0, 0) + SSM(sci, SCI_GETEXTRADESCENT, 0, 0);
+
+ if (g_strcmp0(current.font, cache.font) == 0 &&
+ current.size == cache.size &&
+ current.zoom == cache.zoom &&
+ current.extra == cache.extra)
+ {
+ g_free(current.font);
+ }
+ else
+ {
+ g_free(cache.font);
+ cache = current;
+
+ cache_value = SSM(sci, SCI_TEXTHEIGHT, 0, 0);
+ }
+
+ return cache_value;
+}
+
/* compute margin width based on ratio of line height */
static gint margin_width_from_line_height(ScintillaObject *sci, gdouble ratio, gint threshold)
{
- const gint line_height = SSM(sci, SCI_TEXTHEIGHT, 0, 0);
+ const gint line_height = sci_text_height_cached(sci);
gint width;
width = line_height * ratio;
--------------
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