diff options
author | Owen Taylor <otaylor@redhat.com> | 1998-11-16 23:18:06 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 1998-11-16 23:18:06 +0000 |
commit | 7e44eced8c7c01f60a1135f7de6bd2215d5a3967 (patch) | |
tree | da3d855166a91366d39300791ade23b5b765b9e7 /gtk/gtktext.c | |
parent | d8ab8e0e7d400f8ab41709191e25e42196983861 (diff) | |
download | gtk+-7e44eced8c7c01f60a1135f7de6bd2215d5a3967.tar.gz |
Optimizations for moving point n places. (gtk-mailund-980718-0, Thomas
Mon Nov 16 15:10:33 1998 Owen Taylor <otaylor@redhat.com>
* gtk/gtktext.c: Optimizations for moving point n
places.
(gtk-mailund-980718-0, Thomas Mailund Jensen <mailund@daimi.aau.dk>)
* gtk/gtkfixed.c: Removed gtk_fixed_umap, which was
broken. (GtkWidget's default unmap handler should work fine).
Pointed out by Patrice Fortier <Patrice.Fortier@aquarel.fr>
Diffstat (limited to 'gtk/gtktext.c')
-rw-r--r-- | gtk/gtktext.c | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/gtk/gtktext.c b/gtk/gtktext.c index 4ab73c7b94..b30ea25a9c 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -3232,17 +3232,6 @@ move_mark_n (GtkPropertyMark* mark, gint 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) { TextProperty* prop = MARK_CURRENT_PROPERTY (mark); @@ -3259,6 +3248,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) { mark->index -= 1; @@ -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; } |