From: Nicolas Roche Date: Fri, 25 May 2018 09:05:34 +0000 (+0000) Subject: [Ada] Improve performance of conversion from String to Long_Float X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=529e1a3f522ef75e826309b73d41819cb5da52a4;p=gcc.git [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 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 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 4c6dd1fa1ec..39deb156fc2 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2018-05-25 Nicolas Roche + + * 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 * libgnat/s-parame.ads, libgnat/s-parame__vxworks.ads, diff --git a/gcc/ada/libgnat/s-valrea.adb b/gcc/ada/libgnat/s-valrea.adb index 70f21aafaec..7bc7fd80afe 100644 --- a/gcc/ada/libgnat/s-valrea.adb +++ b/gcc/ada/libgnat/s-valrea.adb @@ -342,7 +342,7 @@ package body System.Val_Real is -- For base 10, use power of ten table, repeatedly if necessary elsif Scale > 0 then - while Scale > Maxpow loop + while Scale > Maxpow and then Uval'Valid loop Uval := Uval * Powten (Maxpow); Scale := Scale - Maxpow; end loop; @@ -350,18 +350,21 @@ package body System.Val_Real is -- Note that we still know that Scale > 0, since the loop -- 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 - while (-Scale) > Maxpow loop + while (-Scale) > Maxpow and then Uval'Valid loop Uval := Uval / Powten (Maxpow); Scale := Scale + Maxpow; end loop; -- Note that we still know that Scale < 0, since the loop -- above leaves Scale in the range -Maxpow .. -1. - - Uval := Uval / Powten (-Scale); + if Uval'Valid then + Uval := Uval / Powten (-Scale); + end if; end if; -- Here is where we check for a bad based number