[gtksourceview] lines: use fast integer to string conversion
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] lines: use fast integer to string conversion
- Date: Thu, 18 Apr 2019 21:39:05 +0000 (UTC)
commit bb42f80f542e50111e6b9693992f9f3f8655e422
Author: Christian Hergert <chergert redhat com>
Date: Thu Apr 18 14:31:18 2019 -0700
lines: use fast integer to string conversion
In the vast majority of cases, we can create a fast path here that uses
internal strings of the library to speed up line number generation instead
of relying on g_snprintf()/gnulib/etc.
The speedup is more noticable on large displays such as HiDPI.
gtksourceview/gtksourcegutterrendererlines.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 20689804..8df6c7d0 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -23,6 +23,7 @@
#endif
#include "gtksourcegutterrendererlines.h"
+#include "gtksourceutils-private.h"
#include "gtksourceview.h"
struct _GtkSourceGutterRendererLinesPrivate
@@ -216,6 +217,7 @@ gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
{
GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
gchar text[24];
+ const gchar *textptr = text;
gint line;
gint len;
gboolean current_line;
@@ -225,17 +227,17 @@ gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
current_line = (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) &&
lines->priv->cursor_visible;
- if (current_line)
+ if G_LIKELY (!current_line)
{
- len = g_snprintf (text, sizeof text, "<b>%d</b>", line);
+ len = _gtk_source_utils_int_to_string (line, &textptr, text);
}
else
{
- len = g_snprintf (text, sizeof text, "%d", line);
+ len = g_snprintf (text, sizeof text, "<b>%d</b>", line);
}
gtk_source_gutter_renderer_text_set_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
- text,
+ textptr,
len);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]