simplified dirty state tracker
parent
a65dda4300
commit
bf9f1167a0
|
@ -2263,35 +2263,6 @@ generic_search_all_buffers(Application_Links *app, General_Memory *general, Part
|
|||
|
||||
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);
|
||||
if (!search_buffer.exists){
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
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);
|
||||
Partition line_part = partition_sub_part(part, (4 << 10));
|
||||
char *str = (char*)partition_current(part);
|
||||
|
|
7
4ed.cpp
7
4ed.cpp
|
@ -1683,11 +1683,12 @@ App_Step_Sig(app_step){
|
|||
file = (Editing_File*)node;
|
||||
|
||||
terminate_with_null(&file->name.source_path);
|
||||
time_stamp =
|
||||
system->file_time_stamp(file->name.source_path.str);
|
||||
time_stamp = system->file_time_stamp(file->name.source_path.str);
|
||||
|
||||
if (time_stamp > 0){
|
||||
file->state.last_sys_write_time = time_stamp;
|
||||
if (file->state.last_sync < time_stamp){
|
||||
file_mark_behind_os(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -886,7 +886,6 @@ DOC_SEE(Buffer_Setting_ID)
|
|||
case BufferSetting_Eol:
|
||||
{
|
||||
file->settings.dos_write_mode = value;
|
||||
file->state.last_4ed_edit_time = system->now_time_stamp();
|
||||
}break;
|
||||
|
||||
case BufferSetting_Unimportant:
|
||||
|
@ -987,6 +986,7 @@ DOC_SEE(Buffer_Create_Flag)
|
|||
if (filename != 0){
|
||||
String filename_string = make_string_terminated(part, filename, filename_len);
|
||||
Editing_File *file = working_set_contains(system, working_set, filename_string);
|
||||
|
||||
if (file == 0){
|
||||
File_Loading loading = {0};
|
||||
|
||||
|
|
45
4ed_file.cpp
45
4ed_file.cpp
|
@ -144,9 +144,7 @@ struct Editing_File_State{
|
|||
Text_Effect paste_effect;
|
||||
|
||||
File_Sync_State sync;
|
||||
u64 last_4ed_write_time;
|
||||
u64 last_4ed_edit_time;
|
||||
u64 last_sys_write_time;
|
||||
u64 last_sync;
|
||||
|
||||
File_Edit_Positions edit_pos_space[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;
|
||||
Editing_File *result = 0;
|
||||
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);
|
||||
|
||||
if (entry){
|
||||
result = working_set_index(working_set, entry->id);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -730,22 +731,14 @@ filename_match(String query, Absolutes *absolutes, String filename, b32 case_sen
|
|||
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
|
||||
buffer_needs_save(Editing_File *file){
|
||||
b32 result = 0;
|
||||
if (file->settings.unimportant == 0)
|
||||
if (buffer_get_sync(file) == SYNC_UNSAVED)
|
||||
if (!file->settings.unimportant){
|
||||
if (file->state.sync == SYNC_UNSAVED){
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -777,7 +770,29 @@ file_set_to_loading(Editing_File *file){
|
|||
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
|
||||
|
||||
|
|
|
@ -844,6 +844,8 @@ file_set_name(Working_Set *working_set, Editing_File *file, char *filename){
|
|||
file_set_name(working_set, file, f);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
inline void
|
||||
file_synchronize_times(System_Functions *system, Editing_File *file, char *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);
|
||||
}
|
||||
#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
|
||||
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);
|
||||
|
||||
file_synchronize_times(system, file, filename);
|
||||
file_mark_clean(file);
|
||||
|
||||
if (used_general){
|
||||
general_memory_free(&mem->general, data);
|
||||
}
|
||||
end_temp_memory(temp);
|
||||
|
||||
file_synchronize_times(system, file);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -1071,10 +1082,9 @@ file_create_from_string(System_Functions *system, Models *models,
|
|||
}
|
||||
|
||||
file_init_strings(file);
|
||||
|
||||
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;
|
||||
file->settings.font_id = font_id;
|
||||
|
@ -1119,6 +1129,8 @@ file_create_from_string(System_Functions *system, Models *models,
|
|||
file->settings.is_initialized = 1;
|
||||
}
|
||||
|
||||
#undef TEST_TIME_MAX
|
||||
|
||||
internal b32
|
||||
file_create_empty(System_Functions *system,
|
||||
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.last_4ed_edit_time = system->now_time_stamp();
|
||||
file_mark_dirty(file);
|
||||
}
|
||||
|
||||
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 (save_as){
|
||||
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();
|
||||
if (result.is_loaded){
|
||||
switch (buffer_get_sync(file)){
|
||||
switch (file_get_sync(file)){
|
||||
case SYNC_GOOD: result.message = message_loaded; break;
|
||||
case SYNC_BEHIND_OS: result.message = message_unsynced; 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{
|
||||
message = string_zero();
|
||||
if (!file->settings.unimportant){
|
||||
switch (buffer_get_sync(file)){
|
||||
switch (file_get_sync(file)){
|
||||
case SYNC_BEHIND_OS: message = message_unsynced; 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();
|
||||
if (!file->settings.unimportant){
|
||||
switch (buffer_get_sync(file)){
|
||||
switch (file_get_sync(file)){
|
||||
case SYNC_BEHIND_OS: message = message_unsynced; 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){
|
||||
switch (buffer_get_sync(file)){
|
||||
switch (file_get_sync(file)){
|
||||
case SYNC_BEHIND_OS:
|
||||
{
|
||||
persist String out_of_sync = make_lit_string(" !");
|
||||
|
|
|
@ -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!
|
||||
|
||||
|
|
|
@ -13,23 +13,28 @@ Allen Webster
|
|||
|
||||
#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_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){
|
||||
TEST_TIME_B();
|
||||
TEST_TIME_B(10000000);
|
||||
|
||||
File_List list = app->get_file_list(app, literal(LOTS_OF_FILES));
|
||||
File_Info *info = list.infos;
|
||||
|
||||
for (int i = 0; i < list.count; ++i, ++info){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -233,6 +233,36 @@ Win32Ptr(void *h){
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue