how many traditional for loops, for which indexed loop proposal applicable, can be converted to foreach
Ruslan Shevchenko
rssh at gradsoft.com.ua
Sat May 2 09:02:24 PDT 2009
Good day, community,
In last statistic data about applicability for indexed loop proposal
(see http://mail.openjdk.java.net/pipermail/coin-dev/2009-April/001614.html)
one question was unanswered:
We have some big percentage of all for traditional loops are loops from
0 to size() [or length]. Question is: are all of them use indexes
(other then in access expressions), or may be some of them can be
converted to JDK foreach loop, but not converted yet for some reason ?
Here is summary data for packages, which was in previous statistics:
jetty hibernate Gwt-users Openjdk-jdk
all traditional fors 315 708 271 11530
convertable to foreach 79 194 29 1515
index other then access 21 191 42 1622
>From 0 to size all 100 385 71 3137
percent of uncovertedd loops 25.08 27.4 10.7 13.14
percent of can-be converted loops with indexes 6.67 26.98 15.5 14.07
So, from 6 to 26 percent of all traditional for loops applicable for
loop-for-each proposal and can't be converted to foreach loops without
one.
Forom 25 to 13 percents of traditional loops can be converted to JDK5
foreach loop.
Or by counts:
jetty:
all traditional fors : 315
for loop (length),convertable to foreach : 63
for loop (size),convertable to foreach : 16
for loop from 0 to size or length : 100
hibernate:
all traditional fors : 708
for loop (length),convertable to foreach : 177
for loop (size),convertable to foreach : 17
for loop from 0 to size or length : 385
gwt-user:
all traditional fors : 271
for loop (length),convertable to foreach : 24
for loop (size),convertable to foreach : 5
for loop from 0 to size or length : 71
openjdk:
all traditional fors : 11530
for loop (length),convertable to foreach : 1515
for loop (size),convertable to foreach : 0
for loop from 0 to size or length : 3137
Patterns for review available in etc/checkers_coin_loop.def
http://redmine.gradsoft.ua/repositories/changes/javachecker/trunk/JavaChecker/etc/checkers_coin_loops.def
If you want run tool on you code, download 2.5.0p4
http://datacenter.gradsoft.ua/public.repository/ua.gradsoft/javachecker/installations/JavaCheckerSourceInstaller-2.5.0p4.jar
Regards !
More information about the coin-dev
mailing list