Re: Most efficient way to iterate through an NSArray
Re: Most efficient way to iterate through an NSArray
- Subject: Re: Most efficient way to iterate through an NSArray
- From: Anjo Krank <email@hidden>
- Date: Mon, 17 Mar 2008 21:16:35 +0100
Ah, I misunderstood what Chuck was trying to say. Yes, this is fixed
in Wonder (also for 5.3). And our toArray also works.
Cheers, Anjo
Am 17.03.2008 um 19:02 schrieb Anjo Krank:
Correct, this was fixed a while ago, but toArray wasn't fixed.
Am 17.03.2008 um 17:58 schrieb Chuck Hill:
Yes, that is a bug on NSArray (I think) that results in the fault
not being fired if you call one of the Java collection methods.
Which, of course, the new Java for loop calls.
It is a Wonder, Wonderful WOrld.
Chuck
On Mar 17, 2008, at 9:55 AM, David Avendasora wrote:
I think I mis-spoke. It doesn't return an array of faults. If the
relationship itself is a fault, simply calling products() without
the .toArray() in a for loop returns a fault and trying to iterate
over it doesn't work.
At least this was the case in 5.3. I haven't tested it in 5.4.
See this pervious thread from almost exactly a year ago:
http://www.mail-archive.com/email@hidden/msg09829.html
Dave
On Mar 17, 2008, at 9:48 AM, Alexander Spohr wrote:
Hey David.
Am 17.03.2008 um 11:41 schrieb David Avendasora:
I find myself often times needing to iterate through an NSArray
of EOs. I'm not sure if the way I'm doing it is the most
effecient or not. Here's what I normally do:
public void doThisForAllProducts(EOEditingContext ec) {
for (Object aProductObject : products().toArray()) {
Product aProduct = (Product) aProductObject;
aProduct.doThis(ec);
}
}
This is assuming that products() is an NSArray of Product EOs.
I'd drop that toArray() as it will not be faster in fetching your
faults than by iterating the NSArrays items. (Or does it
automagicly batchFetch?)
Is this a good / the best way to iterate through NSArrays in
general?
It depends :)
I find myself occasionally nesting this loop a couple deep to
drill down into several toMany relationships. For example (as a
keypath): products.billsOfMaterial.routingSteps.components to
get all the components that are possibly used in a product.
If you know that you have fetched all your products before in
this edcon just run the loops, no faster way available.
The second fastest way to do that is to fetch only the final
array by building an OR-qualifier pointing to your products.
The third fastest way is to batchFetch every array before you
iterate.
On a side note, and the reason for calling products().toArray()
is to force EOF to get the real EOs and not just faults. If I
just call products() I'll sometimes get EOs, sometimes faults,
seemingly by EOF whim. Is that a bug or expected behaviour?
If a product was fetched before it will not be a fault any more.
But why do you care at all if they are faults? Just call doThis()
and EOF will get them for you.
atze
ps. giving doThis an edcon makes me shiver. aProduct already
knows its edcon and should not be allowed to work on a foreign one.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden