String interning
This commit is contained in:
@@ -221,7 +221,7 @@ String GetStyleString(String name, String default_string) {
|
|||||||
defer { lua_pop(LuaState, 1); };
|
defer { lua_pop(LuaState, 1); };
|
||||||
if (lua_isstring(LuaState, -1)) {
|
if (lua_isstring(LuaState, -1)) {
|
||||||
const char *string = lua_tostring(LuaState, -1);
|
const char *string = lua_tostring(LuaState, -1);
|
||||||
result = Copy(Perm, string);
|
result = Intern(&GlobalInternTable, string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -214,10 +214,12 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!FileExists(path)) {
|
if (!FileExists(path)) {
|
||||||
path = GetAbsolutePath(sys_allocator, path);
|
path = GetAbsolutePath(scratch, path);
|
||||||
|
path = Intern(&GlobalInternTable, path);
|
||||||
buffer = CreateBuffer(sys_allocator, path);
|
buffer = CreateBuffer(sys_allocator, path);
|
||||||
} else if (IsDir(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 = CreateBuffer(sys_allocator, path, 4096 * 2);
|
||||||
buffer->is_directory = true;
|
buffer->is_directory = true;
|
||||||
|
|
||||||
@@ -225,7 +227,8 @@ Buffer *BufferOpenFile(String path) {
|
|||||||
IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename));
|
IKnowWhatImDoing_Appendf(buffer, "%.*s ", FmtString(it.filename));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
path = GetAbsolutePath(sys_allocator, path);
|
path = GetAbsolutePath(scratch, path);
|
||||||
|
path = Intern(&GlobalInternTable, path);
|
||||||
String string = ReadFile(scratch, path);
|
String string = ReadFile(scratch, path);
|
||||||
buffer = CreateBuffer(sys_allocator, path, string.len * 4);
|
buffer = CreateBuffer(sys_allocator, path, string.len * 4);
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ int FullScreenPositionX, FullScreenPositionY;
|
|||||||
#include "buffer_fuzzy_search.cpp"
|
#include "buffer_fuzzy_search.cpp"
|
||||||
#include "buffer_test_load.cpp"
|
#include "buffer_test_load.cpp"
|
||||||
|
|
||||||
|
#include "intern_table.cpp"
|
||||||
#include "management.cpp"
|
#include "management.cpp"
|
||||||
#include "window.cpp"
|
#include "window.cpp"
|
||||||
#include "process.cpp"
|
#include "process.cpp"
|
||||||
@@ -83,7 +84,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
|||||||
event.kind = EVENT_TEXT_INPUT;
|
event.kind = EVENT_TEXT_INPUT;
|
||||||
SDL_TextInputEvent &b = input_event->text;
|
SDL_TextInputEvent &b = input_event->text;
|
||||||
String string = b.text;
|
String string = b.text;
|
||||||
event.text = Copy(Perm, string).data; // @leak: @todo: intern table
|
event.text = Intern(&GlobalInternTable, string).data;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
case SDL_EVENT_MOUSE_BUTTON_DOWN: {
|
||||||
@@ -136,7 +137,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
|||||||
event.kind = EVENT_DROP_FILE;
|
event.kind = EVENT_DROP_FILE;
|
||||||
SDL_DropEvent &b = input_event->drop;
|
SDL_DropEvent &b = input_event->drop;
|
||||||
String string = b.data;
|
String string = b.data;
|
||||||
event.text = Copy(Perm, string).data; // @leak
|
event.text = Intern(&GlobalInternTable, string).data;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
// SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, true);
|
// SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, true);
|
||||||
@@ -144,7 +145,7 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
|||||||
// SDL_DropEvent &b = input_event->drop;
|
// SDL_DropEvent &b = input_event->drop;
|
||||||
// event.kind = EVENT_DROP_TEXT;
|
// event.kind = EVENT_DROP_TEXT;
|
||||||
// String string = b.data;
|
// String string = b.data;
|
||||||
// event.text = Copy(Perm, string).data; // @leak
|
// event.text = Intern(&GlobalInternTable, string).data;
|
||||||
// } break;
|
// } break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
|
|||||||
@@ -80,9 +80,7 @@ void ApplyTitleBarChangesToWindow(Window *window, View *view, Buffer *buffer) {
|
|||||||
|
|
||||||
String filepath = ToString(scratch, buffer_string);
|
String filepath = ToString(scratch, buffer_string);
|
||||||
if (filepath != last_buffer->name && !BufferNameExists(filepath)) {
|
if (filepath != last_buffer->name && !BufferNameExists(filepath)) {
|
||||||
// @todo: maybe intern the filenames?
|
last_buffer->name = Intern(&GlobalInternTable, filepath);
|
||||||
// @leak
|
|
||||||
last_buffer->name = Copy(Perm, filepath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Int buffer_pos = XYToPos(*last_buffer, {column, line});
|
Int buffer_pos = XYToPos(*last_buffer, {column, line});
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
- I guess it's pretty dangerous passing pointers everywhere?
|
- Remove pointers and use ViewIDs (enable array debug while doing this)
|
||||||
- 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
|
|
||||||
- try using git grep for search for now, combine with fuzzy search buffer
|
- try using git grep for search for now, combine with fuzzy search buffer
|
||||||
- Test stdin writing code
|
- need to rewrite the path matching in lua
|
||||||
- Implement shell interaction (last line should have a '$'' symbols, if you press enter it should send that line to stdin of a running shell)
|
|
||||||
|
|
||||||
- search as a command to execute which is going to be in the title bar
|
- search as a command to execute which is going to be in the title bar
|
||||||
- search backwards
|
- search backwards
|
||||||
@@ -44,6 +40,8 @@ BUG: there is a click hang when switching windows sometimes, you click after sel
|
|||||||
|
|
||||||
|
|
||||||
backlog
|
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
|
- drop text into window
|
||||||
- page up and down should also scroll and leave you in exactly same scroll
|
- 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)
|
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
|
||||||
|
|||||||
@@ -113,7 +113,9 @@ bool ToggleVisibility(WindowID window_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String BuffCWD(String string) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user