1. Rewrite "structs" to objects.
2. Use container to keep objects. In this case, a Swarm Array
is used:
fcastList=[Array create: [self getZone] setCount: numfcasts];
3. Use standard Swarm approach to "step through" the collection.
Here are a couple of "before" and "after" examples for comparison:
Before: struct BF_fcast *fptr, *topfptr; topfptr = fcast + p->numfcasts; for (fptr = fcast; fptr < topfptr; fptr++) { if (fptr->conditions[0] & real0) continue; *nextptr = fptr; nextptr = &fptr->next; } |
After:
id <Index> index=[ fcastList begin: [self getZone]]; for ( aForecast=[index next]; [index
getLoc]==Member; aForecast=[index next]
) |
//Before //This is an example of a "homemade" list traversal for (fptr=activelist; fptr!=NULL; fptr=fptr->next) { fptr->lastactive = currentTime; if (++fptr->count >= mincount) { ++nactive; if (fptr->strength > maxstrength) { maxstrength = fptr->strength; bestfptr = fptr; } } } |
//After introduction of Swarm collections index=[activeList begin: [self getZone]]; for( aForecast=[index next]; [index getLoc]==Member; aForecast=[index next] ) { [aForecast setLastactive: currentTime]; if([aForecast incrCount] >= mincount) { double strength=[aForecast getStrength]; ++nactive; if (strength > maxstrength) { maxstrength = strength; bestForecast= aForecast; } } } [index drop]; |