-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid parsing opened files when loading project #1289 #1290
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just hope I didn't introduce any stupid memory leak. It's been years since I had to manage memory manually.
@@ -497,13 +509,51 @@ gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file) | |||
} | |||
|
|||
|
|||
static GPtrArray *get_session_files(GKeyFile *config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly stolen from inspired by configuration_load_session_files
in Geany. The only difference is that this one only reads the filename.
f8771f6
to
6cb68a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dolik-rce Thanks! I was hesitating whether this patch doesn't complicate things but it's not too bad so let's do that!
There are some minor comments in the review, nothing major, mostly some renames and minor cleanups.
@@ -532,6 +571,7 @@ void prjorg_project_open(GKeyFile * key_file) | |||
generate_tag_prefs = utils_get_setting_integer(key_file, "prjorg", "generate_tag_prefs", PrjOrgTagAuto); | |||
show_empty_dirs = utils_get_setting_boolean(key_file, "prjorg", "show_empty_dirs", TRUE); | |||
|
|||
open_files = get_session_files(key_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big fat comment here what we are actually doing and why.
@@ -343,6 +345,7 @@ static void update_project( | |||
gchar **header_patterns, | |||
gchar **ignored_dirs_patterns, | |||
gchar **ignored_file_patterns, | |||
gchar **open_files, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session_files
static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) | ||
{ | ||
GHashTableIter iter; | ||
gpointer key, value; | ||
GPtrArray *source_files; | ||
GHashTable *file_table; | ||
gchar **open_files; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest renaming it to session_files
because these aren't open yet and may be confusing.
@@ -292,10 +293,11 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) | |||
gchar *utf8_path = key; | |||
gchar *locale_path = utils_get_locale_from_utf8(utf8_path); | |||
gchar *basename = g_path_get_basename(locale_path); | |||
gboolean is_open = open_files && g_strv_contains(open_files, utf8_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call it will_open
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast open_files
to (const gchar **)
to avoid warnings.
@@ -310,7 +312,7 @@ static void regenerate_tags(PrjOrgRoot *root, gpointer user_data) | |||
} | |||
|
|||
|
|||
void prjorg_project_rescan(void) | |||
void prjorg_project_rescan(gchar **open_files) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to session_files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, I'd suggest converting it to a static function called rescan_project
and having a separate prjorg_project_rescan()
without any arguments and just calling rescan_project(NULL);
inside it. This way you avoid the diffs adding the NULL
parameter across the project.
void prjorg_project_open(GKeyFile * key_file) | ||
{ | ||
gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; | ||
gint generate_tag_prefs; | ||
gboolean show_empty_dirs; | ||
GSList *elem = NULL, *ext_list = NULL; | ||
gchar *utf8_base_path; | ||
GPtrArray *open_files; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session_files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, with the suggested change in get_session_files
, change to gchar **
.
@@ -275,14 +275,15 @@ static GeanyFiletype *filetypes_detect(const gchar *utf8_filename) | |||
return ft; | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep two empty lines before functions
} | ||
g_ptr_array_add(files, NULL); | ||
|
||
return files; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to return g_ptr_array_free(files, FALSE);
and return gchar **
from the function.
@@ -563,6 +604,7 @@ void prjorg_project_open(GKeyFile * key_file) | |||
g_strfreev(ignored_dirs_patterns); | |||
g_strfreev(ignored_file_patterns); | |||
g_strfreev(external_dirs); | |||
g_ptr_array_free(open_files, TRUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use g_strfreev
with the other changes above.
6cb68a7
to
a8c8ca2
Compare
It is even less complicated now, after I applied your suggestions :-) |
Thanks! Merged now. |
Crude but working solution to #1289.
Disclaimer: I'm not really a C person, so any suggestion on how to improve the code quality are most welcome.