aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorHristian Kirtchev <kirtchev@adacore.com>2018-09-26 09:18:23 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-09-26 09:18:23 +0000
commit4f95defaa9c9e60f3e07f629bde8189fb6af19cf (patch)
tree5240b291614aa754bc7f6ef295f95a3c8258f4ab /gcc/ada
parent3e4ade66c6749652de644017de696f9c1e60f3ae (diff)
downloadgcc-4f95defaa9c9e60f3e07f629bde8189fb6af19cf.zip
gcc-4f95defaa9c9e60f3e07f629bde8189fb6af19cf.tar.gz
gcc-4f95defaa9c9e60f3e07f629bde8189fb6af19cf.tar.bz2
[Ada] Pair miscount in Dynamic_HTable.Put
This patch corrects the logic of GNAT.Dynamic_HTables.Dynamic_HTable.Put to update the number of key-value pairs in the hash table only when the put is adding a new pair, rather than updating the value of an existing pair. 2018-09-26 Hristian Kirtchev <kirtchev@adacore.com> gcc/ada/ * libgnat/g-dynhta.adb (Prepend_Or_Replace): Update the number of key-value pairs in the hash table only when adding a brand new pair. gcc/testsuite/ * gnat.dg/dynhash1.adb: New testcase. From-SVN: r264623
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog6
-rw-r--r--gcc/ada/libgnat/g-dynhta.adb10
2 files changed, 14 insertions, 2 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index a93f5df..b9187b6 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,9 @@
+2018-09-26 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * libgnat/g-dynhta.adb (Prepend_Or_Replace): Update the number
+ of key-value pairs in the hash table only when adding a brand
+ new pair.
+
2018-09-26 Sergey Rybin <rybin@adacore.com>
* doc/gnat_ugn/gnat_utility_programs.rst: Add note about
diff --git a/gcc/ada/libgnat/g-dynhta.adb b/gcc/ada/libgnat/g-dynhta.adb
index 004c276..e442514 100644
--- a/gcc/ada/libgnat/g-dynhta.adb
+++ b/gcc/ada/libgnat/g-dynhta.adb
@@ -544,6 +544,9 @@ package body GNAT.Dynamic_HTables is
Detach (Nod);
Free (Nod);
+ -- The number of key-value pairs is updated when the hash table
+ -- contains a valid node which represents the pair.
+
T.Pairs := T.Pairs - 1;
-- Compress the hash table if the load factor drops below
@@ -1121,6 +1124,11 @@ package body GNAT.Dynamic_HTables is
Nod := new Node'(Key, Value, null, null);
Prepend (Nod, Head);
+
+ -- The number of key-value pairs must be updated for a prepend,
+ -- never for a replace.
+
+ T.Pairs := T.Pairs + 1;
end Prepend_Or_Replace;
-- Local variables
@@ -1148,8 +1156,6 @@ package body GNAT.Dynamic_HTables is
Prepend_Or_Replace (Head);
- T.Pairs := T.Pairs + 1;
-
-- Expand the hash table if the ratio of pairs to buckets goes over
-- Expansion_Threshold.