• 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: Why is my code so slow
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is my code so slow


  • Subject: Re: Why is my code so slow
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 29 Nov 2014 00:06:42 -0600

On Nov 28, 2014, at 21:57, David Crowe <email@hidden> wrote:
The following code is incredibly slow if the text string I give it starts with more than 4 or 5 blanks. By the time I'm skipping over 12 blanks, it is taking a second to execute.

Any ideas why? And is there an easier (and faster) way to trim blanks and tabs off a text string?
______________________________________________________________________

Hey David,

Which OSX are you using?  Yosemite?

On my system (10.9.5) your script is quite fast.

If I was going for vanilla AppleScript I'd be more likely to do something like this:

-------------------------------------------------------------------------------------------
on stripLeadingWhitespace(_str)
  set stripCharList to {space, tab}
  set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
  considering case
    repeat with i in (get text items of _str)
      if i is not in stripCharList then
        set AppleScript's text item delimiters to (contents of i)
        set _str to i & (text items 2 thru -1 of _str) as text
        exit repeat
      end if
    end repeat
  end considering
  set AppleScript's text item delimiters to oldTIDS
  return _str
end stripLeadingWhitespace

set _str to "             What are you looking for?  Speed?"
set _str to stripLeadingWhitespace(_str)

-------------------------------------------------------------------------------------------

However.  I much prefer to do text processing with the Satimage.osax and regular expressions:

-------------------------------------------------------------------------------------------
set _str to "             What are you looking for?  Speed?"
set _str to change "^[[:blank:]]+" into "" in _str with regexp
-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: [rant] "Never mind the quality, feel the width!"
  • Next by Date: How do I set folder action in Yosemite, please?
  • Previous by thread: Re: OFF TOPIC: ³Shell Shock² for my system MacOS 10.6.8 bash version 3.2.48(1)
  • Next by thread: Re: Why is my code so slow
  • Index(es):
    • Date
    • Thread