String interning

This commit is contained in:
Krzosa Karol
2024-08-08 11:50:23 +02:00
parent 3488c71155
commit 4434cd5764
6 changed files with 19 additions and 17 deletions

View File

@@ -221,7 +221,7 @@ String GetStyleString(String name, String default_string) {
defer { lua_pop(LuaState, 1); };
if (lua_isstring(LuaState, -1)) {
const char *string = lua_tostring(LuaState, -1);
result = Copy(Perm, string);
result = Intern(&GlobalInternTable, string);
}
}
return result;

View File

@@ -214,10 +214,12 @@ Buffer *BufferOpenFile(String path) {
}
if (!FileExists(path)) {
path = GetAbsolutePath(sys_allocator, path);
path = GetAbsolutePath(scratch, path);
path = Intern(&GlobalInternTable, path);
buffer = CreateBuffer(sys_allocator, path);
} else if (IsDir(path)) {
path = GetAbsolutePath(sys_allocator, path);
path = GetAbsolutePath(scratch, path);
path = Intern(&GlobalInternTable, path);
buffer = CreateBuffer(sys_allocator, path, 4096 * 2);
buffer->is_directory = true;
@@ -225,7 +227,8 @@ Buffer *BufferOpenFile(String path) {
IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename));
}
} else {
path = GetAbsolutePath(sys_allocator, path);
path = GetAbsolutePath(scratch, path);
path = Intern(&GlobalInternTable, path);
String string = ReadFile(scratch, path);
buffer = CreateBuffer(sys_allocator, path, string.len * 4);

View File

@@ -31,6 +31,7 @@ int FullScreenPositionX, FullScreenPositionY;
#include "buffer_fuzzy_search.cpp"
#include "buffer_test_load.cpp"
#include "intern_table.cpp"
#include "management.cpp"
#include "window.cpp"
#include "process.cpp"
@@ -83,7 +84,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
event.kind = EVENT_TEXT_INPUT;
SDL_TextInputEvent &b = input_event->text;
String string = b.text;
event.text = Copy(Perm, string).data; // @leak: @todo: intern table
event.text = Intern(&GlobalInternTable, string).data;
} break;
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
@@ -136,7 +137,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
event.kind = EVENT_DROP_FILE;
SDL_DropEvent &b = input_event->drop;
String string = b.data;
event.text = Copy(Perm, string).data; // @leak
event.text = Intern(&GlobalInternTable, string).data;
} break;
// SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, true);
@@ -144,7 +145,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
// SDL_DropEvent &b = input_event->drop;
// event.kind = EVENT_DROP_TEXT;
// String string = b.data;
// event.text = Copy(Perm, string).data; // @leak
// event.text = Intern(&GlobalInternTable, string).data;
// } break;
default: {

View File

@@ -80,9 +80,7 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) {
String filepath = ToString(scratch, buffer_string);
if (filepath != last_buffer->name && !BufferNameExists(filepath)) {
// @todo: maybe intern the filenames?
// @leak
last_buffer->name = Copy(Perm, filepath);
last_buffer->name = Intern(&GlobalInternTable, filepath);
}
Int buffer_pos = XYToPos(*last_buffer, {column, line});

View File

@@ -1,10 +1,6 @@
- I guess it's pretty dangerous passing pointers everywhere?
- text in events aren't we using invalid memory for text? We need an intern table?
- if exec is prepended with '!' symbol then run a shell command
- Remove pointers and use ViewIDs (enable array debug while doing this)
- try using git grep for search for now, combine with fuzzy search buffer
- Test stdin writing code
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
- need to rewrite the path matching in lua
- search as a command to execute which is going to be in the title bar
- search backwards
@@ -44,6 +40,8 @@ BUG: there is a click hang when switching windows sometimes, you click after sel
backlog
- Test stdin writing code
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
- drop text into window
- page up and down should also scroll and leave you in exactly same scroll
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)

View File

@@ -113,7 +113,9 @@ bool ToggleVisibility(WindowID window_id) {
}
String BuffCWD(String string) {
String result = Format(Perm, "%.*s/%.*s", FmtString(WorkingDir), FmtString(string));
Scratch scratch;
String result = Format(scratch, "%.*s/%.*s", FmtString(WorkingDir), FmtString(string));
result = Intern(&GlobalInternTable, result);
return result;
}