So I'd go for the first method, except where you know you want to squeeze out every ounce of performance.
And FWIW, the first is almost twice as fast in a simple test of your sample here. That's because of the try in the second case, which uses up a bit of time. I probably should have used Cocoaify for and avoided the need.
part 5 : my auxiliary question
After a longer practice of ASObjC Expander, I have the impression that my original handler :
#=====
on sortAndRemoveDuplicates:theList
set anArray to current application's NSArray's arrayWithArray:theList
set theList to (anArray's sortedArrayUsingSelector:"compare:") as list
set theSet to current application's NSOrderedSet's orderedSetWithArray:theList
return theSet's allObjects() as list
end sortAndRemoveDuplicates:
may be enhanced by dropping a list conversion.
#=====
on sortAndRemoveDuplicates:theList
set anArray to current application's NSArray's arrayWithArray:theList
set theList to (anArray's sortedArrayUsingSelector:"compare:") -- as list
set theSet to current application's NSOrderedSet's orderedSetWithArray:theList
return theSet's allObjects() as list
end sortAndRemoveDuplicates:
It works but I want Shane's advice because maybe I missed a collateral effect.
In other scripts I made some changes of this kind. Most of the time it works flawlessly but in some of them the script run once but if I call it a second time the Scripts Editor quits.
In the example above, I was able to cal the handler more than 10 times with no problem.
Yvan KOENIG (VALLAURIS, France) vendredi 22 mai 2015 16:15:25