[gnome-builder] line-changes: avoid GtkTextIter in line change interface
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] line-changes: avoid GtkTextIter in line change interface
- Date: Mon, 28 Aug 2017 19:58:26 +0000 (UTC)
commit f97d8a1555ac4d2261e332ae1a79773c9e62f30e
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 28 12:57:10 2017 -0700
line-changes: avoid GtkTextIter in line change interface
Looking up a GtkTextIter for a given line is actually quite expensive,
even with a BTree for lines. We don't actually need the GtkTextIter anyway
since all we care about is the line number (and the change monitors already
have access to the buffer to convert that into a GtkTextIter).
This shaves off a few % when rendering the gutters.
libide/buffers/ide-buffer-change-monitor.c | 14 +++++---------
libide/buffers/ide-buffer-change-monitor.h | 4 ++--
libide/buffers/ide-buffer.c | 12 ++----------
plugins/git/ide-git-buffer-change-monitor.c | 19 +++++++++----------
4 files changed, 18 insertions(+), 31 deletions(-)
---
diff --git a/libide/buffers/ide-buffer-change-monitor.c b/libide/buffers/ide-buffer-change-monitor.c
index 3f729af..552acc7 100644
--- a/libide/buffers/ide-buffer-change-monitor.c
+++ b/libide/buffers/ide-buffer-change-monitor.c
@@ -39,18 +39,14 @@ static guint signals [LAST_SIGNAL];
IdeBufferLineChange
ide_buffer_change_monitor_get_change (IdeBufferChangeMonitor *self,
- const GtkTextIter *iter)
+ guint line)
{
g_return_val_if_fail (IDE_IS_BUFFER_CHANGE_MONITOR (self), IDE_BUFFER_LINE_CHANGE_NONE);
- g_return_val_if_fail (iter, IDE_BUFFER_LINE_CHANGE_NONE);
- if (IDE_BUFFER_CHANGE_MONITOR_GET_CLASS (self)->get_change)
- return IDE_BUFFER_CHANGE_MONITOR_GET_CLASS (self)->get_change (self, iter);
-
- g_warning ("%s does not implement get_change() vfunc",
- g_type_name (G_TYPE_FROM_INSTANCE (self)));
-
- return IDE_BUFFER_LINE_CHANGE_NONE;
+ if G_LIKELY (IDE_BUFFER_CHANGE_MONITOR_GET_CLASS (self)->get_change)
+ return IDE_BUFFER_CHANGE_MONITOR_GET_CLASS (self)->get_change (self, line);
+ else
+ return IDE_BUFFER_LINE_CHANGE_NONE;
}
static void
diff --git a/libide/buffers/ide-buffer-change-monitor.h b/libide/buffers/ide-buffer-change-monitor.h
index 6f7c200..542ca3c 100644
--- a/libide/buffers/ide-buffer-change-monitor.h
+++ b/libide/buffers/ide-buffer-change-monitor.h
@@ -44,7 +44,7 @@ struct _IdeBufferChangeMonitorClass
void (*set_buffer) (IdeBufferChangeMonitor *self,
IdeBuffer *buffer);
IdeBufferLineChange (*get_change) (IdeBufferChangeMonitor *self,
- const GtkTextIter *iter);
+ guint line);
void (*reload) (IdeBufferChangeMonitor *self);
gpointer _reserved1;
@@ -58,7 +58,7 @@ struct _IdeBufferChangeMonitorClass
};
IdeBufferLineChange ide_buffer_change_monitor_get_change (IdeBufferChangeMonitor *self,
- const GtkTextIter *iter);
+ guint line);
void ide_buffer_change_monitor_emit_changed (IdeBufferChangeMonitor *self);
void ide_buffer_change_monitor_reload (IdeBufferChangeMonitor *self);
diff --git a/libide/buffers/ide-buffer.c b/libide/buffers/ide-buffer.c
index 2906960..be6f9ff 100644
--- a/libide/buffers/ide-buffer.c
+++ b/libide/buffers/ide-buffer.c
@@ -1879,10 +1879,7 @@ ide_buffer_get_line_flags (IdeBuffer *self,
if (priv->change_monitor)
{
- GtkTextIter iter;
-
- gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (self), &iter, line);
- change = ide_buffer_change_monitor_get_change (priv->change_monitor, &iter);
+ change = ide_buffer_change_monitor_get_change (priv->change_monitor, line);
switch (change)
{
@@ -2155,12 +2152,7 @@ ide_buffer_trim_trailing_whitespace (IdeBuffer *self)
IdeBufferLineChange change = IDE_BUFFER_LINE_CHANGE_CHANGED;
if (priv->change_monitor)
- {
- GtkTextIter tmp;
-
- gtk_text_buffer_get_iter_at_line (buffer, &tmp, line);
- change = ide_buffer_change_monitor_get_change (priv->change_monitor, &tmp);
- }
+ change = ide_buffer_change_monitor_get_change (priv->change_monitor, line);
if (change != IDE_BUFFER_LINE_CHANGE_NONE)
{
diff --git a/plugins/git/ide-git-buffer-change-monitor.c b/plugins/git/ide-git-buffer-change-monitor.c
index 122c4e4..fa30e7e 100644
--- a/plugins/git/ide-git-buffer-change-monitor.c
+++ b/plugins/git/ide-git-buffer-change-monitor.c
@@ -178,16 +178,13 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
static IdeBufferLineChange
ide_git_buffer_change_monitor_get_change (IdeBufferChangeMonitor *monitor,
- const GtkTextIter *iter)
+ guint line)
{
IdeGitBufferChangeMonitor *self = (IdeGitBufferChangeMonitor *)monitor;
gpointer key;
gpointer value;
- g_return_val_if_fail (IDE_IS_GIT_BUFFER_CHANGE_MONITOR (self), IDE_BUFFER_LINE_CHANGE_NONE);
- g_return_val_if_fail (iter, IDE_BUFFER_LINE_CHANGE_NONE);
-
- if (!self->state)
+ if (self->state == NULL)
{
/*
* If the file is within the working directory, synthesize line addition.
@@ -197,7 +194,7 @@ ide_git_buffer_change_monitor_get_change (IdeBufferChangeMonitor *monitor,
return IDE_BUFFER_LINE_CHANGE_NONE;
}
- key = GINT_TO_POINTER (gtk_text_iter_get_line (iter) + 1);
+ key = GINT_TO_POINTER (line + 1);
value = g_hash_table_lookup (self->state, key);
return GPOINTER_TO_INT (value);
@@ -300,8 +297,8 @@ ide_git_buffer_change_monitor__buffer_delete_range_cb (IdeGitBufferChangeMonitor
IDE_ENTRY;
g_assert (IDE_IS_GIT_BUFFER_CHANGE_MONITOR (self));
- g_assert (begin);
- g_assert (end);
+ g_assert (begin != NULL);
+ g_assert (end != NULL);
g_assert (IDE_IS_BUFFER (buffer));
/*
@@ -318,7 +315,8 @@ ide_git_buffer_change_monitor__buffer_delete_range_cb (IdeGitBufferChangeMonitor
if (gtk_text_iter_get_line (begin) != gtk_text_iter_get_line (end))
IDE_GOTO (recalculate);
- change = ide_git_buffer_change_monitor_get_change (IDE_BUFFER_CHANGE_MONITOR (self), begin);
+ change = ide_git_buffer_change_monitor_get_change (IDE_BUFFER_CHANGE_MONITOR (self),
+ gtk_text_iter_get_line (begin));
if (change == IDE_BUFFER_LINE_CHANGE_NONE)
IDE_GOTO (recalculate);
@@ -364,7 +362,8 @@ ide_git_buffer_change_monitor__buffer_insert_text_after_cb (IdeGitBufferChangeMo
if (NULL != memmem (text, len, "\n", 1))
IDE_GOTO (recalculate);
- change = ide_git_buffer_change_monitor_get_change (IDE_BUFFER_CHANGE_MONITOR (self), location);
+ change = ide_git_buffer_change_monitor_get_change (IDE_BUFFER_CHANGE_MONITOR (self),
+ gtk_text_iter_get_line (location));
if (change == IDE_BUFFER_LINE_CHANGE_NONE)
IDE_GOTO (recalculate);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]