[evolution-patches] very long line editing.



In trying to reproduce an editor bug I noticed that the editor was
extremely slow rendering very long unbroken lines this patch improves
the speed quite a bit.  Radek please look over the logic carefully, I am
fairly certain it is correct but I'd hate to break something at this
point.

--Larry
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/ChangeLog,v
retrieving revision 1.1783
diff -u -p -r1.1783 ChangeLog
--- ChangeLog	17 Apr 2003 15:10:19 -0000	1.1783
+++ ChangeLog	17 Apr 2003 15:44:28 -0000
@@ -1,3 +1,11 @@
+2003-04-17  Larry Ewing  <lewing ximian com>
+
+	* htmltextslave.c: replace strchr + g_utf8_pointer_to_offset loops
+	with simple loops using g_utf8_next_char to avoid walking the
+	string multiple times (especially in the cases where the entire
+	string was walked each time).   This significantly improves the
+	speed of editing flows with very long unbroken lines.
+
 2003-04-16  Larry Ewing  <lewing ximian com>
 
 	* htmlembedded.c (copy): comment out debug wanring.
Index: htmltextslave.c
===================================================================
RCS file: /cvs/gnome/gtkhtml/src/htmltextslave.c,v
retrieving revision 1.145
diff -u -p -r1.145 htmltextslave.c
--- htmltextslave.c	3 Apr 2003 02:13:41 -0000	1.145
+++ htmltextslave.c	17 Apr 2003 15:44:29 -0000
@@ -107,18 +107,18 @@ get_words_width (HTMLTextSlave *slave, H
 
 	if (html_clueflow_tabs (HTML_CLUEFLOW (HTML_OBJECT (slave)->parent), p)) {
 		gchar *space, *str = html_text_slave_get_text (slave);
-		gint tabs, len, line_offset = html_text_slave_get_line_offset (slave, 0, p);
+		gint line_offset = html_text_slave_get_line_offset (slave, 0, p);
+		gint tabs, len = 0; 
 
 		space = str;
-		while (words && space && *space) {
-			space = strchr (space, ' ');
-			words --;
+		while (words && *space && len < slave->posLen) {
+			if (*space == ' ')
+				words --;
+
+			space = g_utf8_next_char (space);
+			len++;		
 		}
 
-		if (!space || !*space)
-			len = slave->posLen;
-		else
-			len = g_utf8_pointer_to_offset (str, space);
 		/* printf ("width %d --> ", width); */
 		width += html_painter_get_space_width (p, html_text_get_font_style (text), text->face)*(html_text_text_line_length (str, &line_offset, len, &tabs) - len - tabs);
 		/* printf ("%d\n", width); */
@@ -195,6 +195,7 @@ get_offset_for_bounded_width (HTMLTextSl
 	HTMLText *text = slave->owner;
 	gint upper = slave->posLen;
 	gint lower = 0;
+	gint off = 0;
 	gint len, width, asc, dsc;
 	gint line_offset = -1;
 	gchar *sep, *str;
@@ -220,12 +221,12 @@ get_offset_for_bounded_width (HTMLTextSl
 	*words = 0;
 	str = sep = buffer;
 
-	while ((sep = strchr (sep, ' '))) {
-		if (g_utf8_pointer_to_offset (str, sep) < len)
+	while (off < len && *sep) {
+		if (*sep == ' ') 
 			(*words) ++;
-		else
-			break;
-		sep = sep + 1;
+
+		sep = g_utf8_next_char (sep);
+		off++;
 	}
 
 	return len;
@@ -442,7 +443,7 @@ hts_fit_line (HTMLObject *o, HTMLPainter
 	HTMLText *text;
 	HTMLObject *prev;
 	guint  pos = 0;
-	gchar *sep = NULL, *lsep;
+	gchar *sep = NULL;
 	gchar *begin;
 	guint words = 0;
 	gint orig_start_word;
@@ -464,10 +465,17 @@ hts_fit_line (HTMLObject *o, HTMLPainter
 	while ((sep && *sep
 		&& widthLeft >= html_text_slave_nb_width (slave, painter, words + 1))
 	       || (words == 0 && text->words - slave->start_word > 0 && forceFit)) {
+		if (words) {
+			sep = g_utf8_next_char (sep);
+			pos++;
+		}
+		
 		words ++;
-		lsep   = sep;
-		sep    = strchr (lsep + (words > 1 ? 1 : 0), ' ');
-		pos    = sep ? g_utf8_pointer_to_offset (begin, sep) : g_utf8_strlen (begin, -1);
+		while (*sep && *sep != ' ') {
+			sep = g_utf8_next_char (sep);
+			pos++;
+		}
+
 		if (words + slave->start_word >= text->words)
 			break;
 	}
@@ -489,18 +497,23 @@ hts_fit_line (HTMLObject *o, HTMLPainter
 		} else if (slave->start_word + 1 == text->words)
 			rv = next_to_floating ? HTML_FIT_NONE : HTML_FIT_COMPLETE;
 		else {
-			words ++;
+			if (words && *sep) {
+				sep = g_utf8_next_char (sep);
+				pos++;
+			}
 
-			if (sep)
-				sep = strchr (sep + (words > 1 ? 0 : 1), ' ');
+			words ++;
 
-			pos = sep ? g_utf8_pointer_to_offset (begin, sep) : g_utf8_strlen (begin, -1);
+			while (*sep && *sep != ' ') {
+				sep = g_utf8_next_char (sep);
+				pos ++;
+			}
 		}
 	}
 
 	if (rv == HTML_FIT_PARTIAL)
 		if (pos < slave->posLen) {
-			split (slave, pos, slave->start_word + words, sep);
+			split (slave, pos, slave->start_word + words, *sep ? sep : NULL);
 		o->width = get_words_width (slave, painter, words);
 	}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]