Begin garbage collector
This commit is contained in:
@@ -291,7 +291,6 @@ Color GetColor(String name, Color default_color) {
|
||||
return result;
|
||||
}
|
||||
|
||||
BufferID LuaBufferID = {-1};
|
||||
Int LuaBufferChangeID = 0;
|
||||
void ReloadStyle();
|
||||
extern String BaseLuaConfig;
|
||||
|
||||
@@ -7,19 +7,14 @@ Array<ViewID> Views = {};
|
||||
Array<WindowID> Windows = {};
|
||||
|
||||
WindowID NullWindowID;
|
||||
BufferID NullBufferID;
|
||||
BufferID NullBufferID; // +buffer
|
||||
ViewID NullViewID;
|
||||
|
||||
WindowID DebugWindowID;
|
||||
WindowID DebugWindowID; // +debug
|
||||
BufferID DebugBufferID;
|
||||
BufferID LuaBufferID = {-1};
|
||||
|
||||
// @note:
|
||||
// Remember that WindowCommand works on window handed it down from HandleEvent
|
||||
// just because we don't have NextActiveWindow doesn't mean that we work on new
|
||||
// window all of a sudden in that function call!
|
||||
WindowID ActiveWindow;
|
||||
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
|
||||
Int CaretChangeID;
|
||||
WindowID ActiveWindow;
|
||||
|
||||
WindowID ScrollbarSelected = {-1};
|
||||
WindowID DocumentSelected = {-1};
|
||||
@@ -340,3 +335,49 @@ View *WindowOpenBufferView(Window *new_parent_window, String name) {
|
||||
new_parent_window->active_view = result->id;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ViewIsReferenced(ViewID view) {
|
||||
For(Windows) {
|
||||
Window *window = it.o;
|
||||
if (window->active_view == view) return true;
|
||||
if (window->active_goto_list == view) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BufferIsReferenced(BufferID buffer_id) {
|
||||
if (buffer_id == NullBufferID) return true;
|
||||
if (buffer_id == DebugBufferID) return true;
|
||||
if (buffer_id == LuaBufferID) return true;
|
||||
For(Views) {
|
||||
View *view = it.o;
|
||||
if (view->active_buffer == buffer_id) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GarbageCollect() {
|
||||
IterRemove(Views) {
|
||||
IterRemovePrepare(Views);
|
||||
View *view = it.o;
|
||||
if (!ViewIsReferenced(view->id)) {
|
||||
Dealloc(&view->carets);
|
||||
// @todo: add view to free list
|
||||
remove_item = true;
|
||||
}
|
||||
}
|
||||
|
||||
IterRemove(Buffers) {
|
||||
IterRemovePrepare(Buffers);
|
||||
Buffer *buffer = it.o;
|
||||
if (!BufferIsReferenced(buffer->id)) {
|
||||
Dealloc(&buffer->line_starts);
|
||||
Dealloc(&buffer->undo_stack);
|
||||
Dealloc(&buffer->redo_stack);
|
||||
Dealloc(buffer->line_starts.allocator, &buffer->data);
|
||||
// @todo: add buffer to free list
|
||||
remove_item = true;
|
||||
ReportConsolef("collected = %.*s", FmtString(buffer->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,11 +156,6 @@ Event TranslateSDLEvent(SDL_Event *input_event) {
|
||||
return event;
|
||||
}
|
||||
|
||||
void HandleEvent(Event event) {
|
||||
GlobalCommand(event);
|
||||
For(Windows) if (it.o->is_title_bar) ReplaceTitleBarData(it.o);
|
||||
}
|
||||
|
||||
void Update(Event event) {
|
||||
WindowSize = {(float)event.xwindow, (float)event.ywindow};
|
||||
LayoutWindows();
|
||||
@@ -175,11 +170,12 @@ void Update(Event event) {
|
||||
view->update_scroll = true;
|
||||
}
|
||||
|
||||
HandleEvent(event);
|
||||
|
||||
GlobalCommand(event);
|
||||
For(Windows) if (it.o->is_title_bar) ReplaceTitleBarData(it.o);
|
||||
UpdateProcesses();
|
||||
UpdateLua();
|
||||
UpdateDebugBuffer();
|
||||
GarbageCollect();
|
||||
|
||||
For(IterateInReverse(&order)) {
|
||||
Window *window = Windows[it].o;
|
||||
|
||||
Reference in New Issue
Block a user