@b4n commented on this pull request.
> + if (source_file->lang == TM_PARSER_C || source_file->lang ==
> TM_PARSER_CPP)
+ {
+ const gchar **ext;
+ const gchar *common_src_exts[] =
+ {".c", ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++",
".CPP", ".CXX", NULL};
+
+ for (ext = common_src_exts; *ext; ext++)
+ {
+ if (g_str_has_suffix(source_file->short_name, *ext))
+ {
+ source_file->is_c_source = TRUE;
+ break;
+ }
+ }
+ }
+
> Yes, we could do that - makes probably more sense as the `is_source` flag is
> valid for all languages and not specific to C/C++.
Yeah, the main reason I suggest this would be to make the `init_tag()` check
simply `tag->local = tag_entry->isFileScope && file->is_source` rather than
having language-specific tests there as well.
> Does this code offer any benefit compared to what I wrote? I personally find
> my code a bit easier to read as you avoid the extra branch where `.` is not
> found
Merely premature optimization (comparison only compares useful things, and
traverse the basename only once), so no, it doesn't really matter.
If it's only a readability issue, you could easily rewrite this ever so
slightly like so:
```C
source_file->is_source = TRUE;
if (source_file->lang == TM_PARSER_C || source_file->lang ==
TM_PARSER_CPP)
{
const gchar *ext = strrchr(source_file->short_name, '.');
source_file->is_source = FALSE;
if (ext)
{
const gchar *common_src_exts[] =
{"c", "C", "cc", "cp", "cpp", "cxx", "c++",
"CPP", "CXX"};
for (int i = 0; i < G_N_ELEMENTS(common_src_exts); i++)
{
if (strcmp(ext + 1, common_src_exts[i]) == 0)
{
source_file->is_source = TRUE;
break;
}
}
}
}
```
anyway, either way is fine.
--
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/3490#discussion_r1188557639
You are receiving this because you are subscribed to this thread.
Message ID: <geany/geany/pull/3490/review/[email protected]>