Cleanup / optimizations
This commit is contained in:
@@ -6,6 +6,7 @@ std::unordered_map<std::string, std::unique_ptr<LSPInstance>> active_lsps;
|
||||
std::unordered_set<std::string> opened;
|
||||
Queue<std::string> need_opening;
|
||||
std::vector<Editor *> new_editors;
|
||||
Queue<std::unique_ptr<LSPMessage>> response_queue;
|
||||
} // namespace lsp
|
||||
|
||||
void lsp_worker() {
|
||||
|
||||
+29
-22
@@ -44,34 +44,41 @@ int main(int argc, char *argv[]) {
|
||||
std::thread lsp_thread(background_lsp);
|
||||
|
||||
while (running) {
|
||||
KeyEvent event = throttle(1ms, read_key);
|
||||
if (event.key_type != KEY_NONE) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
event.c[0] == CTRL('q')) {
|
||||
free(event.c);
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
if (mode != RUNNER) {
|
||||
if (event.key_type == KEY_MOUSE) {
|
||||
handle_click(event);
|
||||
} else {
|
||||
layout::focused_window->handle_event(event);
|
||||
uint8_t consumed = 0;
|
||||
KeyEvent event;
|
||||
while (++consumed < 32 && (event = read_key()).key_type != KEY_NONE) {
|
||||
if (event.key_type != KEY_NONE) {
|
||||
if (event.key_type == KEY_CHAR && event.len == 1 &&
|
||||
event.c[0] == CTRL('q')) {
|
||||
free(event.c);
|
||||
running = false;
|
||||
goto quit;
|
||||
}
|
||||
} else {
|
||||
ui::bar.handle_event(event);
|
||||
if (mode != RUNNER) {
|
||||
if (event.key_type == KEY_MOUSE) {
|
||||
handle_click(event);
|
||||
} else {
|
||||
layout::focused_window->handle_event(event);
|
||||
}
|
||||
} else {
|
||||
ui::bar.handle_event(event);
|
||||
}
|
||||
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) &&
|
||||
event.c)
|
||||
free(event.c);
|
||||
}
|
||||
if ((event.key_type == KEY_CHAR || event.key_type == KEY_PASTE) &&
|
||||
event.c)
|
||||
free(event.c);
|
||||
}
|
||||
for (auto &lsp_inst : lsp::active_lsps)
|
||||
lsp_inst.second->callbacks();
|
||||
std::unique_ptr<LSPMessage> msg;
|
||||
while (lsp::response_queue.pop(msg)) {
|
||||
msg->callback(*msg);
|
||||
};
|
||||
layout::focused_window->work();
|
||||
throttle(4ms, render);
|
||||
throttle(4ms, io_render);
|
||||
render();
|
||||
throttle(8ms, io_render);
|
||||
}
|
||||
|
||||
quit:
|
||||
|
||||
if (lsp_thread.joinable())
|
||||
lsp_thread.join();
|
||||
|
||||
|
||||
+19
-9
@@ -46,20 +46,26 @@ void Parser::work() {
|
||||
return;
|
||||
std::vector<uint32_t> batch;
|
||||
uint32_t line_count = editor->root->line_count + 1;
|
||||
int64_t start = MIN(scroll_max + 10, line_count - 1);
|
||||
int64_t end = MAX(0, (int64_t)scroll_max - MAX_LINES_LOOKBEHIND);
|
||||
for (int64_t i = start; i >= end; --i) {
|
||||
auto l_opt = line_map.at(i);
|
||||
if (!l_opt || (l_opt && !l_opt->out_state))
|
||||
uint32_t min_line =
|
||||
scroll_max > MAX_LINES_LOOKAROUND ? scroll_max - MAX_LINES_LOOKAROUND : 0;
|
||||
uint32_t max_line = MIN(scroll_max + MAX_LINES_LOOKAROUND, line_count - 1);
|
||||
bool sequential = false;
|
||||
for (uint32_t i = min_line; i <= max_line; ++i) {
|
||||
LineData *ld = line_map.at(i);
|
||||
if ((!ld || !ld->in_state || !ld->out_state) && !sequential) {
|
||||
batch.push_back(i);
|
||||
sequential = true;
|
||||
continue;
|
||||
}
|
||||
sequential = false;
|
||||
}
|
||||
for (uint32_t c_line : batch) {
|
||||
if (!running.load(std::memory_order_relaxed))
|
||||
break;
|
||||
uint32_t min_line = scroll_max > MAX_LINES_LOOKBEHIND
|
||||
? scroll_max - MAX_LINES_LOOKBEHIND
|
||||
uint32_t min_line = scroll_max > MAX_LINES_LOOKAROUND
|
||||
? scroll_max - MAX_LINES_LOOKAROUND
|
||||
: 0;
|
||||
uint32_t max_line = scroll_max + 10;
|
||||
uint32_t max_line = scroll_max + MAX_LINES_LOOKAROUND;
|
||||
if (c_line < min_line || c_line > max_line)
|
||||
continue;
|
||||
uint32_t scroll_snapshot = scroll_max;
|
||||
@@ -78,8 +84,12 @@ void Parser::work() {
|
||||
break;
|
||||
if (scroll_snapshot != scroll_max)
|
||||
break;
|
||||
if (cur_line < min_line || cur_line > max_line)
|
||||
if (cur_line < min_line || cur_line > max_line) {
|
||||
LineData *line_data = line_map.at(cur_line);
|
||||
if (line_data)
|
||||
line_data->out_state = nullptr;
|
||||
break;
|
||||
}
|
||||
uint32_t len;
|
||||
char *line = next_line(it, &len);
|
||||
if (!line)
|
||||
|
||||
Reference in New Issue
Block a user