summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buffer.c9
-rw-r--r--main.c16
-rw-r--r--ted.c1
-rw-r--r--ted.h4
-rw-r--r--text.c6
5 files changed, 19 insertions, 17 deletions
diff --git a/buffer.c b/buffer.c
index b98717d..e2d32ea 100644
--- a/buffer.c
+++ b/buffer.c
@@ -217,9 +217,6 @@ Language buffer_language(TextBuffer *buffer) {
if (!buffer->path)
return LANG_TEXT;
- // @TODO(optimization): cache this?
- // (we're calling buffer_lsp on every edit and that calls this)
-
if (buffer->manual_language != LANG_NONE)
return (Language)buffer->manual_language;
const Settings *settings = buffer->ted->default_settings; // important we don't use buffer_settings here since that would cause a loop!
@@ -277,6 +274,10 @@ LSP *buffer_lsp(TextBuffer *buffer) {
return NULL;
if (buffer->view_only)
return NULL; // we don't really want to start up an LSP in /usr/include
+ if (buffer->ted->frame_time - buffer->last_lsp_check < 1.0) {
+ return ted_get_lsp_by_id(buffer->ted, buffer->lsp_opened_in);
+ }
+
LSP *true_lsp = ted_get_lsp(buffer->ted, buffer->path, buffer_language(buffer));
LSP *curr_lsp = ted_get_lsp_by_id(buffer->ted, buffer->lsp_opened_in);
if (true_lsp != curr_lsp) {
@@ -285,6 +286,7 @@ LSP *buffer_lsp(TextBuffer *buffer) {
if (true_lsp)
buffer_send_lsp_did_open(buffer, true_lsp, NULL);
}
+ buffer->last_lsp_check = buffer->ted->frame_time;
return true_lsp;
}
@@ -2833,6 +2835,7 @@ bool buffer_save_as(TextBuffer *buffer, const char *new_path) {
buffer->frame_latest_line_modified = buffer->nlines - 1;
if (lsp)
buffer_send_lsp_did_close(buffer, lsp, prev_path);
+ buffer->last_lsp_check = -INFINITY;
// we'll send a didOpen the next time buffer_lsp is called.
free(prev_path);
return true;
diff --git a/main.c b/main.c
index 0f9b0e7..d37aedb 100644
--- a/main.c
+++ b/main.c
@@ -1117,13 +1117,6 @@ int main(int argc, char **argv) {
buffer_check_valid(&ted->line_buffer);
#endif
- double frame_end_noswap = time_get_seconds();
- #if PROFILE_FRAME
- {
- print("Frame (noswap): %.1f ms\n", (frame_end_noswap - frame_start) * 1000);
- }
- #endif
-
if (ted->dragging_tab_node)
ted->cursor = ted->cursor_move;
@@ -1135,6 +1128,8 @@ int main(int argc, char **argv) {
SDL_ShowCursor(SDL_DISABLE);
}
+ double frame_end_noswap = time_get_seconds();
+ #if !PROFILE_FRAME
{
// annoyingly, SDL_GL_SwapWindow seems to be a busy loop on my laptop for some reason...
// this is why the framerate-cap settings exists
@@ -1155,8 +1150,13 @@ int main(int argc, char **argv) {
prev_vsync = settings->vsync;
SDL_GL_SetSwapInterval(settings->vsync ? 1 : 0);
}
- SDL_GL_SwapWindow(window);
}
+ #else
+ (void)frame_end_noswap;
+ SDL_GL_SetSwapInterval(0);
+ #endif
+ SDL_GL_SwapWindow(window);
+
PROFILE_TIME(frame_end)
assert(glGetError() == 0);
diff --git a/ted.c b/ted.c
index 1eec19c..56df17d 100644
--- a/ted.c
+++ b/ted.c
@@ -191,6 +191,7 @@ Settings *ted_get_settings(Ted *ted, const char *path, Language language) {
}
LSP *ted_get_lsp_by_id(Ted *ted, LSPID id) {
+ if (id == 0) return NULL;
for (int i = 0; ted->lsps[i]; ++i) {
LSP *lsp = ted->lsps[i];
if (lsp->id == id)
diff --git a/ted.h b/ted.h
index ecd6e89..819001f 100644
--- a/ted.h
+++ b/ted.h
@@ -414,6 +414,10 @@ typedef struct {
/// which LSP this document is open in
LSPID lsp_opened_in;
+ /// determining which LSP to use for a buffer takes some work,
+ /// so we don't want to do it every single frame.
+ /// this keeps track of the last time we actually checked what the correct LSP is.
+ double last_lsp_check;
/// where in the undo history was the last write? used by \ref buffer_unsaved_changes
u32 undo_history_write_pos;
diff --git a/text.c b/text.c
index 70941de..4eb9aaa 100644
--- a/text.c
+++ b/text.c
@@ -9,11 +9,6 @@ no_warn_start
#endif
no_warn_end
-//no_warn_start
-//#define STB_IMAGE_WRITE_IMPLEMENTATION
-//#include "/~/apps/stb/stb_image_write.h"
-//no_warn_end
-
typedef struct {
vec2 pos;
vec2 tex_coord;
@@ -173,7 +168,6 @@ static void font_texture_update_if_needed(FontTexture *texture) {
#if PROFILE
printf("- update font texture: %.1fms\n", 1e3 * (end - start));
#endif
- //stbi_write_png("out.png", FONT_TEXTURE_WIDTH, FONT_TEXTURE_HEIGHT, 1, texture->pixels, FONT_TEXTURE_WIDTH);
texture->needs_update = false;
}
}