Hello there,
I have bumped into a bottleneck in some pretty ancient parts of my code, and am seeking an advice how to fix it. The bottleneck is caused by sorting-and-searching objects of 1:N relationships:
=== my EO code ===
public NSArray orderedPriceOffers {
NSArray offers=priceOffers() // this is a modelled relationship
if (offers==null || offers.count<2) return offers
try {
offers=offers.sortedArrayUsingComparator(new OCSDateComparator())
} catch (Exception exc) {
... never happens anyway, no need to show ...
}
return offers
}
public DBPriceOffer lastValidPriceOffer {
NSArray a=orderedPriceOffers()
if (a==null || a.count==0) return null
for (int n=a.count-1;n>=0;n--) {
DBPriceOffer po=(DBPriceOffer)a.objectAtIndex(n)
if (po.validOffer()) // this is a modelled boolean attribute
return po
}
return null
}
...
@OCStandard class OCSDateComparator extends NSComparator {
public int compare(Object left,Object right) {
DBPriceOffer l=(DBPriceOffer)left,r=(DBPriceOffer)right
return l.creationDate().compare(r.creationDate()) // modelled timestamp attribute, always set creation-time
}
}
===
It would be very beneficial to speed up orderedPriceOffers,