From 7e44eced8c7c01f60a1135f7de6bd2215d5a3967 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Mon, 16 Nov 1998 23:18:06 +0000 Subject: [PATCH] Optimizations for moving point n places. (gtk-mailund-980718-0, Thomas Mon Nov 16 15:10:33 1998 Owen Taylor * gtk/gtktext.c: Optimizations for moving point n places. (gtk-mailund-980718-0, Thomas Mailund Jensen ) * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was broken. (GtkWidget's default unmap handler should work fine). Pointed out by Patrice Fortier --- ChangeLog | 10 ++++++ ChangeLog.pre-2-0 | 10 ++++++ ChangeLog.pre-2-10 | 10 ++++++ ChangeLog.pre-2-2 | 10 ++++++ ChangeLog.pre-2-4 | 10 ++++++ ChangeLog.pre-2-6 | 10 ++++++ ChangeLog.pre-2-8 | 10 ++++++ gtk/gtkfixed.c | 11 ------- gtk/gtktext.c | 82 +++++++++++++++++++++++++++------------------- 9 files changed, 118 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 326bcbb2ee..9ff3fd9334 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +Mon Nov 16 15:10:33 1998 Owen Taylor + + * gtk/gtktext.c: Optimizations for moving point n + places. + (gtk-mailund-980718-0, Thomas Mailund Jensen ) + + * gtk/gtkfixed.c: Removed gtk_fixed_umap, which was + broken. (GtkWidget's default unmap handler should work fine). + Pointed out by Patrice Fortier + Mon Nov 16 00:59:26 PST 1998 Manish Singh * gtk/gtkmenubar.[ch]: added shadow_type setting and diff --git a/gtk/gtkfixed.c b/gtk/gtkfixed.c index 47c9d01de2..799d9159d2 100644 --- a/gtk/gtkfixed.c +++ b/gtk/gtkfixed.c @@ -22,7 +22,6 @@ static void gtk_fixed_class_init (GtkFixedClass *klass); static void gtk_fixed_init (GtkFixed *fixed); static void gtk_fixed_map (GtkWidget *widget); -static void gtk_fixed_unmap (GtkWidget *widget); static void gtk_fixed_realize (GtkWidget *widget); static void gtk_fixed_size_request (GtkWidget *widget, GtkRequisition *requisition); @@ -87,7 +86,6 @@ gtk_fixed_class_init (GtkFixedClass *class) parent_class = gtk_type_class (GTK_TYPE_CONTAINER); widget_class->map = gtk_fixed_map; - widget_class->unmap = gtk_fixed_unmap; widget_class->realize = gtk_fixed_realize; widget_class->size_request = gtk_fixed_size_request; widget_class->size_allocate = gtk_fixed_size_allocate; @@ -214,15 +212,6 @@ gtk_fixed_map (GtkWidget *widget) } } -static void -gtk_fixed_unmap (GtkWidget *widget) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_FIXED (widget)); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); -} - static void gtk_fixed_realize (GtkWidget *widget) { diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 4ab73c7b94..b30ea25a9c 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -3231,17 +3231,6 @@ move_mark_n (GtkPropertyMark* mark, gint n) decrement_mark_n(mark, -n); } -static void -advance_mark_n (GtkPropertyMark* mark, gint n) -{ - gint i; - - g_assert (n > 0); - - for (i = 0; i < n; i += 1) - advance_mark (mark); -} - static void advance_mark (GtkPropertyMark* mark) { @@ -3258,6 +3247,37 @@ advance_mark (GtkPropertyMark* mark) } } +static void +advance_mark_n (GtkPropertyMark* mark, gint n) +{ + gint i; + TextProperty* prop; + + g_assert (n > 0); + + i = 0; /* otherwise it migth not be init. */ + prop = MARK_CURRENT_PROPERTY(mark); + + if ((prop->length - mark->offset - 1) < n) { /* if we need to change prop. */ + /* to make it easier */ + n += (mark->offset); + mark->index -= mark->offset; + mark->offset = 0; + /* first we take seven-mile-leaps to get to the right text + * property. */ + while ((n-i) > prop->length - 1) { + i += prop->length; + mark->index += prop->length; + mark->property = MARK_NEXT_LIST_PTR (mark); + prop = MARK_CURRENT_PROPERTY (mark); + } + } + + /* and then the rest */ + mark->index += n - i; + mark->offset += n - i; +} + static void decrement_mark (GtkPropertyMark* mark) { @@ -3275,25 +3295,28 @@ decrement_mark (GtkPropertyMark* mark) static void decrement_mark_n (GtkPropertyMark* mark, gint n) { - gint i; - g_assert (n > 0); - - for (i = 0; i < n; i += 1) - decrement_mark (mark); -} + while (mark->offset < n) { + /* jump to end of prev */ + n -= mark->offset + 1; + mark->index -= mark->offset + 1; + mark->property = MARK_PREV_LIST_PTR (mark); + mark->offset = MARK_CURRENT_PROPERTY (mark)->length - 1; + } + + /* and the rest */ + mark->index -= n; + mark->offset -= n; +} + static GtkPropertyMark find_mark (GtkText* text, guint mark_position) { return find_mark_near (text, mark_position, &text->point); } -/* This can be optimized in two ways. - * First, advances can be made in units of the current TextProperty - * length, when possible. This will reduce computation and function - * call overhead. - * +/* * You can also start from the end, what a drag. */ static GtkPropertyMark @@ -3324,18 +3347,9 @@ find_mark_near (GtkText* text, guint mark_position, const GtkPropertyMark* near) mark.property = text->text_properties; mark.offset = 0; } - - if (mark.index > mark_position) - { - while (mark.index > mark_position) - decrement_mark (&mark); - } - else - { - while (mark_position > mark.index) - advance_mark (&mark); - } - + + move_mark_n (&mark, mark_position - mark.index); + return mark; }