simplified dirty state tracker

This commit is contained in:
Allen Webster 2016-07-20 11:19:54 -04:00
parent a65dda4300
commit bf9f1167a0
8 changed files with 132 additions and 65 deletions

View File

@ -2263,35 +2263,6 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part
Search_Range *ranges = set.ranges; Search_Range *ranges = set.ranges;
{
View_Summary view = app->get_active_view(app, AccessProtected);
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, AccessProtected);
int j = 0;
if (buffer.exists){
ranges[0].type = SearchRange_FrontToBack;
ranges[0].flags = match_flags;
ranges[0].buffer = buffer.buffer_id;
ranges[0].start = 0;
ranges[0].size = buffer.size;
j = 1;
}
for (Buffer_Summary buffer_it = app->get_buffer_first(app, AccessAll);
buffer_it.exists;
app->get_buffer_next(app, &buffer_it, AccessAll)){
if (buffer.buffer_id != buffer_it.buffer_id){
ranges[j].type = SearchRange_FrontToBack;
ranges[j].flags = match_flags;
ranges[j].buffer = buffer_it.buffer_id;
ranges[j].start = 0;
ranges[j].size = buffer_it.size;
++j;
}
}
set.count = j;
}
Buffer_Summary search_buffer = app->get_buffer_by_name(app, literal("*search*"), AccessAll); Buffer_Summary search_buffer = app->get_buffer_by_name(app, literal("*search*"), AccessAll);
if (!search_buffer.exists){ if (!search_buffer.exists){
search_buffer = app->create_buffer(app, literal("*search*"), BufferCreate_AlwaysNew); search_buffer = app->create_buffer(app, literal("*search*"), BufferCreate_AlwaysNew);
@ -2303,6 +2274,39 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part
app->buffer_replace_range(app, &search_buffer, 0, search_buffer.size, 0, 0); app->buffer_replace_range(app, &search_buffer, 0, search_buffer.size, 0, 0);
} }
{
View_Summary view = app->get_active_view(app, AccessProtected);
Buffer_Summary buffer = app->get_buffer(app, view.buffer_id, AccessProtected);
int j = 0;
if (buffer.exists){
if (buffer.buffer_id != search_buffer.buffer_id){
ranges[0].type = SearchRange_FrontToBack;
ranges[0].flags = match_flags;
ranges[0].buffer = buffer.buffer_id;
ranges[0].start = 0;
ranges[0].size = buffer.size;
j = 1;
}
}
for (Buffer_Summary buffer_it = app->get_buffer_first(app, AccessAll);
buffer_it.exists;
app->get_buffer_next(app, &buffer_it, AccessAll)){
if (buffer.buffer_id != buffer_it.buffer_id){
if (search_buffer.buffer_id != buffer_it.buffer_id){
ranges[j].type = SearchRange_FrontToBack;
ranges[j].flags = match_flags;
ranges[j].buffer = buffer_it.buffer_id;
ranges[j].start = 0;
ranges[j].size = buffer_it.size;
++j;
}
}
}
set.count = j;
}
Temp_Memory temp = begin_temp_memory(part); Temp_Memory temp = begin_temp_memory(part);
Partition line_part = partition_sub_part(part, (4 << 10)); Partition line_part = partition_sub_part(part, (4 << 10));
char *str = (char*)partition_current(part); char *str = (char*)partition_current(part);

View File

@ -1683,11 +1683,12 @@ App_Step_Sig(app_step){
file = (Editing_File*)node; file = (Editing_File*)node;
terminate_with_null(&file->name.source_path); terminate_with_null(&file->name.source_path);
time_stamp = time_stamp = system->file_time_stamp(file->name.source_path.str);
system->file_time_stamp(file->name.source_path.str);
if (time_stamp > 0){ if (time_stamp > 0){
file->state.last_sys_write_time = time_stamp; if (file->state.last_sync < time_stamp){
file_mark_behind_os(file);
}
} }
} }
} }

View File

@ -886,7 +886,6 @@ DOC_SEE(Buffer_Setting_ID)
case BufferSetting_Eol: case BufferSetting_Eol:
{ {
file->settings.dos_write_mode = value; file->settings.dos_write_mode = value;
file->state.last_4ed_edit_time = system->now_time_stamp();
}break; }break;
case BufferSetting_Unimportant: case BufferSetting_Unimportant:
@ -987,6 +986,7 @@ DOC_SEE(Buffer_Create_Flag)
if (filename != 0){ if (filename != 0){
String filename_string = make_string_terminated(part, filename, filename_len); String filename_string = make_string_terminated(part, filename, filename_len);
Editing_File *file = working_set_contains(system, working_set, filename_string); Editing_File *file = working_set_contains(system, working_set, filename_string);
if (file == 0){ if (file == 0){
File_Loading loading = {0}; File_Loading loading = {0};

View File

@ -144,9 +144,7 @@ struct Editing_File_State{
Text_Effect paste_effect; Text_Effect paste_effect;
File_Sync_State sync; File_Sync_State sync;
u64 last_4ed_write_time; u64 last_sync;
u64 last_4ed_edit_time;
u64 last_sys_write_time;
File_Edit_Positions edit_pos_space[16]; File_Edit_Positions edit_pos_space[16];
File_Edit_Positions *edit_poss[16]; File_Edit_Positions *edit_poss[16];
@ -566,10 +564,13 @@ working_set_contains(System_Functions *system, Working_Set *working_set, String
File_Entry *entry = 0; File_Entry *entry = 0;
Editing_File *result = 0; Editing_File *result = 0;
working_set__entry_comp(system, filename, &entry_comp); working_set__entry_comp(system, filename, &entry_comp);
entry = (File_Entry*)table_find_item(&working_set->table, &entry_comp, system, tbl_string_hash, tbl_file_compare); entry = (File_Entry*)table_find_item(&working_set->table, &entry_comp, system, tbl_string_hash, tbl_file_compare);
if (entry){ if (entry){
result = working_set_index(working_set, entry->id); result = working_set_index(working_set, entry->id);
} }
return(result); return(result);
} }
@ -730,22 +731,14 @@ filename_match(String query, Absolutes *absolutes, String filename, b32 case_sen
return result; return result;
} }
inline File_Sync_State
buffer_get_sync(Editing_File *file){
File_Sync_State result = SYNC_GOOD;
if (file->state.last_4ed_write_time != file->state.last_sys_write_time)
result = SYNC_BEHIND_OS;
else if (file->state.last_4ed_edit_time > file->state.last_sys_write_time)
result = SYNC_UNSAVED;
return result;
}
inline b32 inline b32
buffer_needs_save(Editing_File *file){ buffer_needs_save(Editing_File *file){
b32 result = 0; b32 result = 0;
if (file->settings.unimportant == 0) if (!file->settings.unimportant){
if (buffer_get_sync(file) == SYNC_UNSAVED) if (file->state.sync == SYNC_UNSAVED){
result = 1; result = 1;
}
}
return(result); return(result);
} }
@ -777,7 +770,29 @@ file_set_to_loading(Editing_File *file){
file->is_loading = 1; file->is_loading = 1;
} }
inline void
file_mark_clean(Editing_File *file){
if (file->state.sync != SYNC_BEHIND_OS){
file->state.sync = SYNC_GOOD;
}
}
inline void
file_mark_dirty(Editing_File *file){
if (file->state.sync != SYNC_BEHIND_OS){
file->state.sync = SYNC_UNSAVED;
}
}
inline void
file_mark_behind_os(Editing_File *file){
file->state.sync = SYNC_BEHIND_OS;
}
inline File_Sync_State
file_get_sync(Editing_File *file){
return (file->state.sync);
}
// BOTTOM // BOTTOM

View File

@ -844,6 +844,8 @@ file_set_name(Working_Set *working_set, Editing_File *file, char *filename){
file_set_name(working_set, file, f); file_set_name(working_set, file, f);
} }
#if 0
inline void inline void
file_synchronize_times(System_Functions *system, Editing_File *file, char *filename){ file_synchronize_times(System_Functions *system, Editing_File *file, char *filename){
u64 stamp = system->file_time_stamp(filename); u64 stamp = system->file_time_stamp(filename);
@ -854,6 +856,13 @@ file_synchronize_times(System_Functions *system, Editing_File *file, char *filen
} }
file->state.sync = buffer_get_sync(file); file->state.sync = buffer_get_sync(file);
} }
#endif
inline void
file_synchronize_times(System_Functions *system, Editing_File *file){
file->state.last_sync = system->now_time_stamp();
file->state.sync = SYNC_GOOD;
}
internal b32 internal b32
file_save(System_Functions *system, Mem_Options *mem, Editing_File *file, char *filename){ file_save(System_Functions *system, Mem_Options *mem, Editing_File *file, char *filename){
@ -897,13 +906,15 @@ file_save(System_Functions *system, Mem_Options *mem, Editing_File *file, char *
result = system->file_save(filename, data, size); result = system->file_save(filename, data, size);
file_synchronize_times(system, file, filename); file_mark_clean(file);
if (used_general){ if (used_general){
general_memory_free(&mem->general, data); general_memory_free(&mem->general, data);
} }
end_temp_memory(temp); end_temp_memory(temp);
file_synchronize_times(system, file);
return(result); return(result);
} }
@ -1071,10 +1082,9 @@ file_create_from_string(System_Functions *system, Models *models,
} }
file_init_strings(file); file_init_strings(file);
file_set_name(working_set, file, (char*)name); file_set_name(working_set, file, (char*)name);
file_synchronize_times(system, file, name); file_synchronize_times(system, file);
i16 font_id = models->global_font.font_id; i16 font_id = models->global_font.font_id;
file->settings.font_id = font_id; file->settings.font_id = font_id;
@ -1119,6 +1129,8 @@ file_create_from_string(System_Functions *system, Models *models,
file->settings.is_initialized = 1; file->settings.is_initialized = 1;
} }
#undef TEST_TIME_MAX
internal b32 internal b32
file_create_empty(System_Functions *system, file_create_empty(System_Functions *system,
Models *models, Editing_File *file, char *filename){ Models *models, Editing_File *file, char *filename){
@ -2020,7 +2032,7 @@ file_pre_edit_maintenance(System_Functions *system,
} }
file->state.still_lexing = 0; file->state.still_lexing = 0;
} }
file->state.last_4ed_edit_time = system->now_time_stamp(); file_mark_dirty(file);
} }
struct Cursor_Fix_Descriptor{ struct Cursor_Fix_Descriptor{
@ -3251,7 +3263,7 @@ view_save_file(System_Functions *system, Models *models,
} }
} }
if (file && (buffer_get_sync(file) != SYNC_GOOD || save_as)){ if (file && (file_get_sync(file) != SYNC_GOOD || save_as)){
if (file_save(system, mem, file, filename_string.str)){ if (file_save(system, mem, file, filename_string.str)){
if (save_as){ if (save_as){
file_set_name(working_set, file, filename_string.str); file_set_name(working_set, file, filename_string.str);
@ -3745,7 +3757,7 @@ get_exhaustive_info(System_Functions *system, Working_Set *working_set, Exhausti
result.message = string_zero(); result.message = string_zero();
if (result.is_loaded){ if (result.is_loaded){
switch (buffer_get_sync(file)){ switch (file_get_sync(file)){
case SYNC_GOOD: result.message = message_loaded; break; case SYNC_GOOD: result.message = message_loaded; break;
case SYNC_BEHIND_OS: result.message = message_unsynced; break; case SYNC_BEHIND_OS: result.message = message_unsynced; break;
case SYNC_UNSAVED: result.message = message_unsaved; break; case SYNC_UNSAVED: result.message = message_unsaved; break;
@ -4565,7 +4577,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
else{ else{
message = string_zero(); message = string_zero();
if (!file->settings.unimportant){ if (!file->settings.unimportant){
switch (buffer_get_sync(file)){ switch (file_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break; case SYNC_UNSAVED: message = message_unsaved; break;
} }
@ -4586,7 +4598,7 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
message = string_zero(); message = string_zero();
if (!file->settings.unimportant){ if (!file->settings.unimportant){
switch (buffer_get_sync(file)){ switch (file_get_sync(file)){
case SYNC_BEHIND_OS: message = message_unsynced; break; case SYNC_BEHIND_OS: message = message_unsynced; break;
case SYNC_UNSAVED: message = message_unsaved; break; case SYNC_UNSAVED: message = message_unsaved; break;
} }
@ -5659,7 +5671,7 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re
} }
if (!file->settings.unimportant){ if (!file->settings.unimportant){
switch (buffer_get_sync(file)){ switch (file_get_sync(file)){
case SYNC_BEHIND_OS: case SYNC_BEHIND_OS:
{ {
persist String out_of_sync = make_lit_string(" !"); persist String out_of_sync = make_lit_string(" !");

View File

@ -1,4 +1,4 @@
Distribution Date: 18.7.2016 (dd.mm.yyyy) Distribution Date: 20.7.2016 (dd.mm.yyyy)
Thank you for contributing to the 4coder project! Thank you for contributing to the 4coder project!

View File

@ -13,23 +13,28 @@ Allen Webster
#define LOTS_OF_FILES "w:/4ed/data/lots_of_files" #define LOTS_OF_FILES "w:/4ed/data/lots_of_files"
#define TEST_TIME_B()
#define TEST_TIME_E()
#include "4coder_default_include.cpp" #include "4coder_default_include.cpp"
#include "4coder_default_building.cpp" #include "4coder_default_building.cpp"
#include <Windows.h>
// NOTE(allen): This timing restriction is based on 4GHz and 60fps
// 4G / 60 ~= 70M Reserving most of that time for rendering and hopefully idling
// I set the goal of 10M for all tests.
#define TEST_TIME_B(m) DWORD64 time_start = __rdtsc(), time_max = m
#define TEST_TIME_E() DWORD64 time_total = __rdtsc() - time_start; if (time_total > time_max) {assert(!"failed timing");}
#define TEST_TIME_M(m) m = (float)(__rdtsc() - time_start) / time_max
CUSTOM_COMMAND_SIG(load_lots_of_files){ CUSTOM_COMMAND_SIG(load_lots_of_files){
TEST_TIME_B(); TEST_TIME_B(10000000);
File_List list = app->get_file_list(app, literal(LOTS_OF_FILES)); File_List list = app->get_file_list(app, literal(LOTS_OF_FILES));
File_Info *info = list.infos; File_Info *info = list.infos;
for (int i = 0; i < list.count; ++i, ++info){ for (int i = 0; i < list.count; ++i, ++info){
if (!info->folder){ if (!info->folder){
app->create_buffer(app, info->filename, info->filename_len, BufferCreate_Background); app->create_buffer(app, info->filename, info->filename_len,
BufferCreate_Background | BufferCreate_AlwaysNew);
} }
} }

View File

@ -233,6 +233,36 @@ Win32Ptr(void *h){
return(result); return(result);
} }
//
// Rudimentary Timing
//
#define WIN32_TIMING 0
#if FRED_INTERNAL && WIN32_TIMING
inline void
show_debug_timing(char *function, DWORD64 total){
char output[512];
String out = make_fixed_width_string(output);
append(&out, function);
append(&out, ' ');
append_u64_to_str(&out, (u64)(total));
append(&out, '\n');
terminate_with_null(&out);
OutputDebugStringA(output);
}
#define TEST_TIME_B() DWORD64 start = __rdtsc()
#define TEST_TIME_E() DWORD64 total = __rdtsc() - start; show_debug_timing(__FUNCTION__, total)
#else
#define TEST_TIME_B()
#define TEST_TIME_E()
#endif
// //
// Memory (not exposed to application, but needed in system_shared.cpp) // Memory (not exposed to application, but needed in system_shared.cpp)