]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Avoid repeated range checks when negating a rational number
authorPiotr Trojanek <trojanek@adacore.com>
Thu, 27 Feb 2025 10:44:54 +0000 (11:44 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 6 Jun 2025 08:37:16 +0000 (10:37 +0200)
Use local constant to avoid repeated range checks (at least in the debug
builds), but also to make the code easier to read and consistent in style
with similar routines in the same package.

gcc/ada/ChangeLog:

* urealp.adb (UR_Negate): Capture array element in a local constant.

gcc/ada/urealp.adb

index 3a9fddea60b5925a863f5ed502fa652335c7c93c..d5fb4f55be7d66a027aaf51037fd8204c7615c98 100644 (file)
@@ -1237,12 +1237,13 @@ package body Urealp is
    ---------------
 
    function UR_Negate (Real : Ureal) return Ureal is
+      Val : constant Ureal_Entry := Ureals.Table (Real);
    begin
       return Store_Ureal
-               ((Num      => Ureals.Table (Real).Num,
-                 Den      => Ureals.Table (Real).Den,
-                 Rbase    => Ureals.Table (Real).Rbase,
-                 Negative => not Ureals.Table (Real).Negative));
+               ((Num      => Val.Num,
+                 Den      => Val.Den,
+                 Rbase    => Val.Rbase,
+                 Negative => not Val.Negative));
    end UR_Negate;
 
    ------------