compiler optimizations
1 posts in topic
Flat View  Flat View

Posted By:   nuno_oliveira
Posted On:   Monday, October 21, 2002 11:13 AM

Can anyone tell me if in the following code, the compiler abolishes the need for size() recalculation ?

java.util.Vector v = new java.util.Vector();

v.add(new Integer(1));

v.add(new Integer(2));

for (int i = 0; i < v.size(); ++i)


int a = 1; //or whatever instruction that

// doesn't modify v



Re: compiler optimizations

Posted By:   eimi_nos  
Posted On:   Monday, October 21, 2002 04:14 PM

With a variable for size, i.e.,

int size = v.size();
for(int i = 0; size; i++){}

it seems to work significantly faster than for(int i=0;v.size();i++){} under the supposition that v is not altered.
About | Sitemap | Contact