qemacs-commit
[Top][All Lists]
Advanced

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

[Qemacs-commit] qemacs qe.c


From: Charlie Gordon
Subject: [Qemacs-commit] qemacs qe.c
Date: Tue, 13 May 2014 08:56:23 +0000

CVSROOT:        /sources/qemacs
Module name:    qemacs
Changes by:     Charlie Gordon <chqrlie>        14/05/13 08:56:23

Modified files:
        .              : qe.c 

Log message:
        improve auto colorizing system
        
        * improve colorization speed on (very) large files
        * use geometric progression instead of linear to reallocate state buffer
        * fix bug that caused states to get lost when displaying previous pages

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.c?cvsroot=qemacs&r1=1.167&r2=1.168

Patches:
Index: qe.c
===================================================================
RCS file: /sources/qemacs/qemacs/qe.c,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -b -r1.167 -r1.168
--- qe.c        29 Apr 2014 22:29:56 -0000      1.167
+++ qe.c        13 May 2014 08:56:23 -0000      1.168
@@ -3267,7 +3267,7 @@
                                int *offsetp, int line_num)
 {
     QEColorizeContext cctx;
-    int len, l, line, col, offset, bom;
+    int len, line, n, col, offset, bom;
 
     /* invalidate cache if needed */
     if (s->colorize_max_valid_offset != INT_MAX) {
@@ -3280,11 +3280,17 @@
 
     /* realloc state array if needed */
     if ((line_num + 2) > s->colorize_nb_lines) {
-        s->colorize_nb_lines = line_num + 2 + COLORIZED_LINE_PREALLOC_SIZE;
+        /* Reallocate colorization state buffer with pseudo-Fibonacci
+         * geometric progression (ratio of 1.625)
+         */
+        n = max(s->colorize_nb_lines, COLORIZED_LINE_PREALLOC_SIZE);
+        while (n < (line_num + 2))
+            n += (n >> 1) + (n >> 3);
         if (!qe_realloc(&s->colorize_states,
-                        s->colorize_nb_lines * sizeof(*s->colorize_states))) {
+                        n * sizeof(*s->colorize_states))) {
             return 0;
         }
+        s->colorize_nb_lines = n;
     }
 
     memset(&cctx, 0, sizeof(cctx));
@@ -3300,14 +3306,14 @@
         cctx.colorize_state = s->colorize_states[s->colorize_nb_valid_lines - 
1];
         cctx.state_only = 1;
 
-        for (l = s->colorize_nb_valid_lines; l <= line_num; l++) {
+        for (line = s->colorize_nb_valid_lines; line <= line_num; line++) {
             len = eb_get_line(s->b, buf, buf_size - 1, &offset);
             /* skip byte order mark if present */
             bom = (len > 0 && buf[0] == 0xFEFF);
             s->colorize_func(&cctx, buf + bom, len - bom, s->mode_flags);
             /* buf[len] has char '\0' but may hold style, force buf ending */
             buf[len + 1] = 0;
-            s->colorize_states[l] = cctx.colorize_state;
+            s->colorize_states[line] = cctx.colorize_state;
         }
     }
 
@@ -3322,7 +3328,10 @@
     /* XXX: if state is same as previous, minimize invalid region? */
     s->colorize_states[line_num + 1] = cctx.colorize_state;
 
+    /* Extend valid area */
+    if (s->colorize_nb_valid_lines < line_num + 2)
     s->colorize_nb_valid_lines = line_num + 2;
+
     return len;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]