• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: really slow repeat loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: really slow repeat loop


  • Subject: Re: really slow repeat loop
  • From: Andrew Oliver <email@hidden>
  • Date: Tue, 18 Jan 2005 17:37:53 -0800

On 1/18/05 4:17 PM, "Gabe Benveniste" <email@hidden> wrote:

> I'm doing this loop in AppleScript Studio but was told this was more of
> an applescript issue in general.
>
> This loop is REALLY slow and I'm looking for a way to make it faster.
>
>     set theRows to every data row in theDataSource
>     display dialog "checking"
>     
>     repeat with theRow in theRows
>         set is_checked to the contents of the data cell "checkbox_row"
> of theRow
>         set username to the contents of the data cell "username" of
> theRow
>         
>         if is_checked is true then
>             set end of user_list to username
>         end if
>     end repeat
>
>

As has been covered many times before, when appending to a list it is far,
far faster to:

   copy username to end of user_list

Since it involves less memory moving, especially with large lists.

Then, the next obvious change would be to change so that you're only getting
the username where needs be:

repeat with theRow in theRows
    set is_checked to the contents of data cell "checkbox_row" of theRow
        
    if is_checked is true then
      copy contents of data cell "username" of theRow to end of user_list
    end if
 end repeat

In other words, don't both extracting the username unless you know you'll
need it. It's not a big change, but it might make a difference.

The second solution is potentially bigger, depending on the data in
question. Try using a 'whose' clause to just get the relevant rows directly
rather than getting them all and iterating through (watch for line wraps):

 set theRows to every data row in theDataSource whose data cell
"checkbox_row" is true

Now you know you have relevant rows, so just set the user_list accordingly:

 repeat with eachRow in theRows
   copy contents of data cell "username" of theRow to end of user_list
 end repeat

You may also be able to:

 set user_list to contents of data cell "username" of theRows

to get them all at once.

Andrew
:)

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: really slow repeat loop
      • From: "Shane Stanley" <email@hidden>
References: 
 >really slow repeat loop (From: Gabe Benveniste <email@hidden>)

  • Prev by Date: Re: really slow repeat loop
  • Next by Date: Re: really slow repeat loop
  • Previous by thread: Re: really slow repeat loop
  • Next by thread: Re: really slow repeat loop
  • Index(es):
    • Date
    • Thread