]> git.mdlowis.com Git - projs/tide.git/commitdiff
speed improvement for files with lots of long lines
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 19 Apr 2018 17:26:20 +0000 (13:26 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 19 Apr 2018 17:26:20 +0000 (13:26 -0400)
lib/view.c

index 00d210efebc5e8f3a2a59ff9199375c54499ce0b..aec966d628e53ba4550102c4aada192ed782e819 100644 (file)
@@ -109,6 +109,7 @@ static void resize(View* view, size_t width, size_t nrows, size_t off) {
     view->width = width;
     view->nvisible = nrows;
     off = buf_bol(&(view->buffer), off);
+    bool first_line_done = false;
     for (size_t i = 0; nrows > 0; i++) {
         view->nrows++;
         view->rows = realloc(view->rows, sizeof(Row*) * view->nrows);
@@ -120,7 +121,8 @@ static void resize(View* view, size_t width, size_t nrows, size_t off) {
             int rune = buf_getrat(&(view->buffer), off);
             size_t rwidth = rune_width(rune, xpos, width);
             xpos += rwidth;
-            if (rune == '\n') nrows--;
+            if (!first_line_done)
+                first_line_done = (rune == '\n');
             if (xpos <= width) {
                 size_t len = view->rows[view->nrows-1]->len + 1;
                 view->rows[view->nrows-1] = realloc(
@@ -131,6 +133,8 @@ static void resize(View* view, size_t width, size_t nrows, size_t off) {
                 off = buf_byrune(&(view->buffer), off, RIGHT);
             }
         }
+        if (first_line_done)
+            nrows--;
     }
 }