]> git.ipfire.org Git - thirdparty/gcc.git/commit
[Ada] Get rid of linear searches in Lib
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:48:33 +0000 (09:48 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 20 Aug 2019 09:48:33 +0000 (09:48 +0000)
commitc20c73fab8baa36ccbbe53857c390a36ee0271ee
treeab6094d07f2fb6054eb06f98d82d1bf1d63ad42f
parent697113bd1efec0ff3e94b492f7f6a7c1a662926a
[Ada] Get rid of linear searches in Lib

This change is aimed at removing a couple of linear searches in the
units management code that can become problematic performance-wise when
the number of loaded units is in the several hundreds, which can happen
for large files even at -O0 without any inlining.

It introduces an auxiliary hash table to record a mapping between the
name of units and their entry in the units table, and then replaces the
linear searches by lookups in this names table.  This can save up to 2%
of the compilation time spent in the front-end in some cases.

There should be no functional changes, except in the error message
issued for circular unit dependencies in very peculiar and convoluted
cases.

2019-08-20  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

* lib.ads: Add with clause for GNAT.HTable.
Add pragma Inline for Is_Loaded and alphabetize the list.
(Unit_Name_Table_Size): New constant.
(Unit_Name_Header_Num): New subtype.
(Unit_Name_Hash): New function declaration.
(Unit_Names): New simple hash table.
(Init_Unit_Name): New procedure declaration.
* lib.adb (Set_Unit_Name): Unregister the old name in the table,
if any, and then register the new name.
(Init_Unit_Name): New procedure.
(Is_Loaded): Reimplement using a lookup in the names table.
(Remove_Unit): Unregister the name.
(Unit_Name_Hash): New function.
* lib-load.adb (Create_Dummy_Package_Unit): Call Init_Unit_Name.
(Load_Unit): Use a lookup in the names table to find out whether
the unit has already been loaded.  Call Init_Unit_Name and then
Remove_Unit if the loading has failed.
(Make_Child_Decl_Unit): Call Init_Unit_Name.
(Make_Instance_Unit): Likewise.
* lib-writ.adb (Ensure_System_Dependency): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274720 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ada/ChangeLog
gcc/ada/lib-load.adb
gcc/ada/lib-writ.adb
gcc/ada/lib.adb
gcc/ada/lib.ads