mcedit: file loading speed up.

Apply direct line counting during file reading.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-08-08 15:44:12 +04:00
parent 13c8f5213b
commit 9ea1ed08c6
2 changed files with 17 additions and 6 deletions

View File

@ -167,9 +167,7 @@ edit_load_file_fast (edit_buffer_t * buf, const vfs_path_t * filename_vpath)
}
ret = (edit_buffer_read_file (buf, file, buf->size) == buf->size);
if (ret)
buf->lines = edit_buffer_count_lines (buf, 0, buf->size);
else
if (!ret)
{
gchar *errmsg;

View File

@ -640,10 +640,11 @@ off_t
edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
{
off_t ret = 0;
off_t i;
off_t i, j;
off_t data_size;
void *b;
buf->lines = 0;
buf->curs2 = size;
i = buf->curs2 >> S_EDIT_BUF_SIZE;
@ -653,10 +654,16 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
{
b = g_malloc0 (EDIT_BUF_SIZE);
g_ptr_array_add (buf->b2, b);
ret = mc_read (fd, (char *) b + EDIT_BUF_SIZE - data_size, data_size);
b = (char *) b + EDIT_BUF_SIZE - data_size;
ret = mc_read (fd, b, data_size);
/* count lines */
for (j = 0; j < ret; j++)
if (*((char *) b + j) == '\n')
buf->lines++;
if (ret < 0 || ret != data_size)
return ret;
}
/* fulfill other parts of b2 from end to begin */
@ -670,6 +677,12 @@ edit_buffer_read_file (edit_buffer_t * buf, int fd, off_t size)
sz = mc_read (fd, b, data_size);
if (sz >= 0)
ret += sz;
/* count lines */
for (j = 0; j < sz; j++)
if (*((char *) b + j) == '\n')
buf->lines++;
if (sz != data_size)
break;
}