Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Oberon > Re: Optimizatio...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 5 Topic 447 of 500
Post > Topic >>

Re: Optimization question

by "Chris Burrows" <cfbsoftware@[EMAIL PROTECTED] > Nov 3, 2007 at 09:52 AM

"Xcriber51" <ken@[EMAIL PROTECTED]
> wrote in message 
news:c023969500341664fb6f74665bbb79e9@[EMAIL PROTECTED]
> Hi
>
> A very minor detail.
>
> If I used a for loop as below, referring to a string 's' (whose length
> doesn't change in the routine),...
>
>    FOR i := 0 TO LEN(s$)-1 DO...
>
> ..does BlackBox optimize the expression "LEN(s$)-1" so that it doesn't
> recalculate it at every iteration, or do we have to eliminate that
> manually thus...
>
>    len := LEN(s$)-1;
>    FOR i := 0 TO len DO ...
>

I haven't inspected the code generated or checked the compiler source but
if 
BlackBox was not optimizing the for loop then it would not be in
conformance 
with the Component Pascal Language re****t. The definition of a FOR loop in

Section 9.8 of the re****t is:

==============================
FOR v := beg TO end BY step DO statements END

is equivalent to

temp := end; v := beg;
IF step > 0 THEN
  WHILE v <= temp DO statements; INC(v, step) END
ELSE
  WHILE v >= temp DO statements; INC(v, step) END
END

==============================

i.e. the end value is only evaluated once before the loop starts.

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp
 




 5 Posts in Topic:
Optimization question
"Xcriber51" <  2007-11-02 08:01:52 
Re: Optimization question
Stefano Ferrari <ferra  2007-11-02 06:38:18 
Re: Optimization question
"Xcriber51" <  2007-11-02 15:14:23 
Re: Optimization question
"Xcriber51" <  2007-11-03 03:55:25 
Re: Optimization question
"Chris Burrows"  2007-11-03 09:52:33 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 9:41:03 CDT 2008.