With the previous TMWorkspace API it was possible to make the workspace
inconsistent by e.g. removing source files and forgetting to update
workspace. This could lead to non-obvious and not immediately visible
crashes.
The new set of the public (but also Geany private) API calls always
updates the workspace accordingly and neither of the calls can lead
to an inconsistent state of the workspace.
In addition, perform some minor cleanups and simplifications - unify
parsing from buffer and from file, support "parsing" of 0-sized buffers
and improve documentation.
Manage the list the same way as workspace tags_array by the fast tag removal
and merge. Thanks to this, typename tags don't have to be extracted from
tags_array periodically, which speeds up editing.
Even though the binary search requires expensive string comparisons,
there are just log(n) of them to find the tag in the workspace array
and the result is much faster than scanning the array linearly (this
of course works only under the condition that
len(source_file->tags_array) << len(workspace_array)
This is however satisfied for big projects (and doesn't matter for small
projects).
Also make the tm_tags_find() function more user friendly by returning
tagCount 0 when no tags found.
Instead of qsort() it's possible to use g_ptr_array_sort_with_data() with
similar performance. Unfortunately it seems there's no bsearch_with_data()
anywhere so the patch uses a modified bsearch() implementation from libc
(still probably cleaner than passing arguments using static variables).
Lazy initializing various member pointers doesn't bring any real performance
improvement but it requires lots of additional NULL checks - get rid of
this.
Make some more cleanups on the way.
In addition, remove success/failure return values from tm_workspace_add_source_file()
and tm_workspace_remove_source_file() which have no real use.
Avoid "utility" parameters like do_free for which we already have API calls
and which actually don't perform any free if the source file isn't
in TM. Clarify when to set the update_workspace parameter.
The placement of this function in tm_source_file is not right - by moving
it to the workspace we can make the source file unaware of the existence
of the workspace (no inclusion of tm_workspace.h in tm_source_file any
more). Also change tm_source_file_new() so it doesn't offer the source file
update.
After this change
* TMWorkspace knows TMSourceFile and TMTag
* TMSourceFile knows TMTag
* TMTag knows TMSourceFile
This makes it less confusing for code accessing TMTag so it can always
find the language in tag->lang and there is no need to access it through
tag->file.lang.
The union on TMTag is very confusing and rather dangerous. The fields
file/timestamp and line/lang overlap. Some implicit assumptions are made
in the code - timestamp is never set so when file is NULL, the file
struct should be used to get the lang member. Rather avoid using unions
and move the lang member to the entry struct together with the other
attributes.
Similarly, add #if TM_DEBUG around various unused debugging functions.
The #if 0 surrounded functions are good candidate for future removal
if decided they are not needed any more.
Since both the file tags and workspace tags are sorted, it is unnecessary
to completely resort the tags for the workspace - instead, remove the
tags belonging to the file from the workspace tags and merge the updated
file's tags into the workspace tags.
The merge is optimized for merging small number of tags into a large array.
For instance, the total number of tags in linux kernel is about 2300000
while the average number of tags per file is about 65 (35000 source files).
Most of the time merge won't be performed so we can avoid expensive
string comparisons and try to make bigger jumps to see if some merge is
needed or not (more details in the source file comments).
In addition, rename all functions, parameters, comments etc. mentioning
work_object and remove unnecessary parameters of various functions.
Delete dead code paths.
Also move common functions like tm_get_real_path() from tm_work_object to
tm_source_file.
Only manually uninstall the files we manually installed, as
uninstall-local might be run in parallel to Automake's own uninstall
targets.
We don't uninstall the directories as some docs seems to suggest
`rmdir` isn't really portable. Anyway, Automake don't uninstall
directories either so it's not a real problem.
An alternative solution would be to keep the recursive removal of
`$(DOCDIR)` but move it to `uninstall-hook`, which is guaranteed to be
run after other uninstall rules. However, recursive deletion is not
always sensible as it might remove files we didn't install, e.g. if the
user added them manually.