From: "Jean-Pierre Rosen" <rosen.adalog@wanadoo.fr>
Subject: Re: Right of Optimize Eager Evaluation Away
Date: 1999/11/29
Date: 1999-11-29T18:41:38+00:00 [thread overview]
Message-ID: <81uhd2$nl4$1@wanadoo.fr> (raw)
In-Reply-To: 863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1511 bytes --]
Laurent Guerby <guerby@acm.org> a �crit dans le message :
863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr...
> [I originally posted this in the 11.6 thread, but got no answer]
>
> If we have the following function:
>
> function Cond_T (C : in Boolean; If_True, If_False : in T) return T;
> pragma Inline (Cond_T);
>
> function Cond_T (C : in Boolean; If_True, If_False : in T) return T is
> begin
> if C then
> return If_True;
> else
> return If_False;
> end if;
> end Cond_T;
>
> And the following expression:
>
> C : constant Boolean :=
Some_Run_Time_Value_That_The_Compiler_Cannot_Guess;
>
> X : constant T := Cont_T (C, If_True =>
Super_Expensive_Function_Call_1,
> If_False =>
Super_Expensive_Function_Call_2);
>
> The question is: is a smart Ada 95 compiler allowed to generate code
> that looks like this:
>
> if C then
> X := Super_Expensive_Function_Call_1;
> else
> X := Super_Expensive_Function_Call_2;
> end if;
>
> that is to say, be lazy about its argument, and so might
> save execution time.
>
The simplest solution in this case would be to pass pointers to the
Super_Expensive_Function_Calls;
This way, only the *pointers* are evaluated at the call, the functions are
actually called only as necessary...
--
---------------------------------------------------------
J-P. Rosen (Rosen.Adalog@wanadoo.fr)
Visit Adalog's web site at http://pro.wanadoo.fr/adalog
prev parent reply other threads:[~1999-11-29 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-11-28 0:00 Right of Optimize Eager Evaluation Away Laurent Guerby
1999-11-28 0:00 ` Robert A Duff
1999-11-28 0:00 ` Laurent Guerby
1999-11-29 0:00 ` Nick Roberts
1999-11-29 0:00 ` Robert A Duff
1999-11-29 0:00 ` Laurent Guerby
1999-11-29 0:00 ` Niklas Holsti
1999-11-29 0:00 ` Robert A Duff
1999-11-30 0:00 ` Laurent Guerby
1999-11-29 0:00 ` Lutz Donnerhacke
1999-11-29 0:00 ` Jean-Pierre Rosen [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox