CE big performance improvements
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m18s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m18s
This commit is contained in:
87
ce/edit.c
87
ce/edit.c
@@ -82,6 +82,8 @@ static bool prepare_lines_cb (void* ctx, const char* start, size_t len) {
|
|||||||
if (editor.current_line == NULL)
|
if (editor.current_line == NULL)
|
||||||
editor.current_line = line;
|
editor.current_line = line;
|
||||||
|
|
||||||
|
editor.total_lines++;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +101,8 @@ static void update_vert_scroll (size_t screen_rows) {
|
|||||||
if (editor.cursor.line < editor.row_offset)
|
if (editor.cursor.line < editor.row_offset)
|
||||||
editor.row_offset = editor.cursor.line;
|
editor.row_offset = editor.cursor.line;
|
||||||
|
|
||||||
if (editor.cursor.line >= editor.row_offset + (screen_rows - 1))
|
if (editor.cursor.line >= editor.row_offset + screen_rows)
|
||||||
editor.row_offset = editor.cursor.line - (screen_rows - 1) + 1;
|
editor.row_offset = editor.cursor.line - screen_rows + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t count_digits (size_t n) {
|
static size_t count_digits (size_t n) {
|
||||||
@@ -131,30 +133,24 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
bool edit_run = true;
|
bool edit_run = true;
|
||||||
|
|
||||||
while (edit_run) {
|
while (edit_run) {
|
||||||
update_horz_scroll (cols);
|
size_t gutter_width = count_digits (editor.total_lines);
|
||||||
update_vert_scroll (rows);
|
size_t effective_cols = (cols > gutter_width) ? cols - gutter_width : cols;
|
||||||
|
|
||||||
int w;
|
update_horz_scroll (effective_cols);
|
||||||
const size_t backbuffer_max = 128 * 1024;
|
update_vert_scroll (rows - 1);
|
||||||
size_t bb_remaining = backbuffer_max;
|
|
||||||
|
const size_t backbuffer_max = 256 * 1024;
|
||||||
char* backbuffer = arena_malloc (&temp_arena, backbuffer_max);
|
char* backbuffer = arena_malloc (&temp_arena, backbuffer_max);
|
||||||
memset (backbuffer, 0, backbuffer_max);
|
|
||||||
char* bbptr = backbuffer;
|
char* bbptr = backbuffer;
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, ANSIQ_CUR_HOME);
|
memcpy (bbptr, ANSIQ_CUR_HOME, sizeof (ANSIQ_CUR_HOME) - 1);
|
||||||
bbptr += w;
|
bbptr += sizeof (ANSIQ_CUR_HOME) - 1;
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
size_t lines_drawn = 0;
|
size_t lines_drawn = 0;
|
||||||
size_t current_idx = 0;
|
size_t current_idx = 0;
|
||||||
|
|
||||||
struct list_node_link *line_link, *tmp_line_link;
|
struct list_node_link *line_link, *tmp_line_link;
|
||||||
|
|
||||||
list_foreach (editor.lines, line_link, tmp_line_link) editor.total_lines++;
|
|
||||||
|
|
||||||
size_t gutter_width = count_digits (editor.total_lines);
|
|
||||||
size_t effective_cols = (cols > gutter_width + 3) ? cols - (gutter_width + 3) : cols;
|
|
||||||
|
|
||||||
list_foreach (editor.lines, line_link, tmp_line_link) {
|
list_foreach (editor.lines, line_link, tmp_line_link) {
|
||||||
if (current_idx < editor.row_offset) {
|
if (current_idx < editor.row_offset) {
|
||||||
current_idx++;
|
current_idx++;
|
||||||
@@ -166,14 +162,9 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
|
|
||||||
struct edit_line* line = list_entry (line_link, struct edit_line, lines_link);
|
struct edit_line* line = list_entry (line_link, struct edit_line, lines_link);
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR_LINE);
|
bbptr += snprintf (bbptr, (backbuffer_max - (bbptr - backbuffer)),
|
||||||
bbptr += w;
|
ANSIQ_SCR_CLR_LINE LINE_NUMBERS_STYLE "%*zu" ANSIQ_GR_RESET,
|
||||||
bb_remaining -= w;
|
(int)gutter_width, current_idx + 1);
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, LINE_NUMBERS_STYLE " %*zu " ANSIQ_GR_RESET " ",
|
|
||||||
(int)gutter_width, current_idx + 1);
|
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
size_t part1_len = line->gb.gap_start;
|
size_t part1_len = line->gb.gap_start;
|
||||||
size_t part2_len = line->gb.size - line->gb.gap_end;
|
size_t part2_len = line->gb.size - line->gb.gap_end;
|
||||||
@@ -187,9 +178,8 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
if (len > effective_cols)
|
if (len > effective_cols)
|
||||||
len = effective_cols;
|
len = effective_cols;
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, "%.*s", (int)len, &line->gb.buffer[start]);
|
memcpy (bbptr, &line->gb.buffer[start], len);
|
||||||
bbptr += w;
|
bbptr += len;
|
||||||
bb_remaining -= w;
|
|
||||||
current_col += len;
|
current_col += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,43 +194,28 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
if (current_col + len > effective_cols)
|
if (current_col + len > effective_cols)
|
||||||
len = effective_cols - current_col;
|
len = effective_cols - current_col;
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, "%.*s", (int)len,
|
memcpy (bbptr, &line->gb.buffer[line->gb.gap_end + skip], len);
|
||||||
&line->gb.buffer[line->gb.gap_end + skip]);
|
bbptr += len;
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR2END "\n");
|
bbptr += snprintf (bbptr, (backbuffer_max - (bbptr - backbuffer)), ANSIQ_SCR_CLR2END "\n");
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
lines_drawn++;
|
lines_drawn++;
|
||||||
current_idx++;
|
current_idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, ANSIQ_DYN_CUR_SET ANSIQ_SCR_CLR_LINE, (int)rows, 1);
|
bbptr += snprintf (bbptr, (backbuffer_max - (bbptr - backbuffer)),
|
||||||
bbptr += w;
|
ANSIQ_DYN_CUR_SET ANSIQ_SCR_CLR_LINE STATUS_LINE_STYLE
|
||||||
bb_remaining -= w;
|
"%*s" ANSIQ_DYN_CUR_SET
|
||||||
|
" Editing %s; line %zu col %zu; Mode: %s" ANSIQ_GR_RESET ANSIQ_DYN_CUR_SET
|
||||||
|
ANSIQ_CUR_VISIBLE,
|
||||||
|
(int)rows, 1, (int)cols, "", (int)rows, 1, file_path, editor.cursor.line + 1,
|
||||||
|
editor.cursor.col + 1, string_modes[editor.mode],
|
||||||
|
(int)(editor.cursor.line - editor.row_offset) + 1,
|
||||||
|
(int)(editor.cursor.col - editor.col_offset) + 1 + (int)gutter_width);
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, STATUS_LINE_STYLE "%*s" ANSIQ_DYN_CUR_SET, (int)cols, "",
|
mail_send (e_pgid, backbuffer, bbptr - backbuffer);
|
||||||
(int)rows, 1);
|
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, " Editing %s; line %zu col %zu; Mode: %s" ANSIQ_GR_RESET,
|
|
||||||
file_path, editor.cursor.line + 1, editor.cursor.col + 1,
|
|
||||||
string_modes[editor.mode]);
|
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
w = snprintf (bbptr, bb_remaining, ANSIQ_DYN_CUR_SET ANSIQ_CUR_VISIBLE,
|
|
||||||
(int)(editor.cursor.line - editor.row_offset) + 1,
|
|
||||||
(int)(editor.cursor.col - editor.col_offset) + 1 + (int)gutter_width + 3);
|
|
||||||
bbptr += w;
|
|
||||||
bb_remaining -= w;
|
|
||||||
|
|
||||||
mail_send (e_pgid, backbuffer, strlen (backbuffer));
|
|
||||||
|
|
||||||
uint8_t ch = 0;
|
uint8_t ch = 0;
|
||||||
mail_receive (&ch, 1);
|
mail_receive (&ch, 1);
|
||||||
@@ -291,6 +266,7 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
editor.cursor.col = 0;
|
editor.cursor.col = 0;
|
||||||
editor.cursor.line++;
|
editor.cursor.line++;
|
||||||
editor.current_line = new_line;
|
editor.current_line = new_line;
|
||||||
|
editor.total_lines++;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case KB_DELETE:
|
case KB_DELETE:
|
||||||
@@ -361,7 +337,6 @@ void edit_start (const char* file_path, const char* text) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.total_lines = 0;
|
|
||||||
arena_reset (&temp_arena);
|
arena_reset (&temp_arena);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user