Commit 529e1a3f by Nicolas Roche Committed by Pierre-Marie de Rodat

[Ada] Improve performance of conversion from String to Long_Float

Once it is sure that the result will be infinity, stop computation and return
the result. This ensure that the function call duration is bounded. Before that
change on some cases the computation was taking more than a few seconds.

2018-05-25  Nicolas Roche  <roche@adacore.com>

gcc/ada/

	* libgnat/s-valrea.adb (Scan_Real): Abort computation once it is sure
	that the result will be either -infinite or +infinite.

From-SVN: r260743
parent 38806cd3
2018-05-25 Nicolas Roche <roche@adacore.com>
* libgnat/s-valrea.adb (Scan_Real): Abort computation once it is sure
that the result will be either -infinite or +infinite.
2018-05-25 Patrick Bernardi <bernardi@adacore.com> 2018-05-25 Patrick Bernardi <bernardi@adacore.com>
* libgnat/s-parame.ads, libgnat/s-parame__vxworks.ads, * libgnat/s-parame.ads, libgnat/s-parame__vxworks.ads,
......
...@@ -342,7 +342,7 @@ package body System.Val_Real is ...@@ -342,7 +342,7 @@ package body System.Val_Real is
-- For base 10, use power of ten table, repeatedly if necessary -- For base 10, use power of ten table, repeatedly if necessary
elsif Scale > 0 then elsif Scale > 0 then
while Scale > Maxpow loop while Scale > Maxpow and then Uval'Valid loop
Uval := Uval * Powten (Maxpow); Uval := Uval * Powten (Maxpow);
Scale := Scale - Maxpow; Scale := Scale - Maxpow;
end loop; end loop;
...@@ -350,18 +350,21 @@ package body System.Val_Real is ...@@ -350,18 +350,21 @@ package body System.Val_Real is
-- Note that we still know that Scale > 0, since the loop -- Note that we still know that Scale > 0, since the loop
-- above leaves Scale in the range 1 .. Maxpow. -- above leaves Scale in the range 1 .. Maxpow.
Uval := Uval * Powten (Scale); if Uval'Valid then
Uval := Uval * Powten (Scale);
end if;
elsif Scale < 0 then elsif Scale < 0 then
while (-Scale) > Maxpow loop while (-Scale) > Maxpow and then Uval'Valid loop
Uval := Uval / Powten (Maxpow); Uval := Uval / Powten (Maxpow);
Scale := Scale + Maxpow; Scale := Scale + Maxpow;
end loop; end loop;
-- Note that we still know that Scale < 0, since the loop -- Note that we still know that Scale < 0, since the loop
-- above leaves Scale in the range -Maxpow .. -1. -- above leaves Scale in the range -Maxpow .. -1.
if Uval'Valid then
Uval := Uval / Powten (-Scale); Uval := Uval / Powten (-Scale);
end if;
end if; end if;
-- Here is where we check for a bad based number -- Here is where we check for a bad based number
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment