Re: Reformatting a string
Re: Reformatting a string
- Subject: Re: Reformatting a string
- From: Thomas Fischer <email@hidden>
- Date: Mon, 30 Jan 2012 15:17:09 +0100
Hi Shane,
thanks for the test.
It looks like the time the script needs grows essentially exponentially with the length of text. I don't see any obvious reason for this, it must be some inefficiency inside AppleScript. The most time in my script is actually used by the conversion
set aChar to aChar as text
which shouldn't be needed to begin with and shouldn't need much time either.
But I found I can speed up the script very considerably (factor 10?) by using an additional reference:
set theChars to every character in inText # faster with longer texts
set theCharsRef to a reference to theChars
repeat with aChar in theCharsRef
…
For some reason that stops
set aChar to aChar as text
from eating up the time.
Best
Thomas
Am 30.01.2012 um 13:17 schrieb Shane Stanley:
> On 30/01/2012, at 10:19 PM, Thomas Fischer wrote:
>
>> I would be glad to know how this compares to the other options. Shane, can you check this?
>
> It's faster than SmartStrings, but it still has the same problem of taking ages with longer strings. I tried a 5Kb string before I started typing this reply, and it's still running[1] -- Satimage and ASObjC Runner took between 1 and 3 seconds for the same thing. I just can't see any amount of clever tweaking bridging that sort of gap.
>
>> I get an empty string outText as a result: the aChar copied to the end of the list isn't a character anymore.
>> theChars and the list outText look identical, but aren't. Is this a bug or a feature?
>
> This is known behavior: outText is a list of references, not characters. They're getting resolved in logging, but not in the coercion to text.
>>
>> By the way, there is an error in Yvan's solution: if you
>>> set unID to id of unCarac
>> then unID isn't necessarily a number
>
> SmartString makes the same assumption, so it will break there too.
>
> This really underlines why, IMO, this should be built into AS. It's not really the speed -- AS is slower, and we all know that and live with it. It's just that it's so easy to get wrong, even by people who know AS back-to-front and inside-out, and in ways that appear to be working.
>
> It's not like it would involve a lot of code; it just has to pass on the functionality of Cocoa strings, which use the ICU library to do it all in open-source C.
>
> FWIW, I broke down and logged a feature request on bugreporter requesting lowercase/uppercase commands. I'm not holding my breath, but maybe a modest chorus would bring it to someone's attention.
>
>> So if you want to have full control of the action and no additional software installed
>
> Keep in mind that using AppleScriptObjC and saving as a Cocoa-AppleScript app technically meets that spec, at least for apps.
>
> [1] I knew if I typed long enough: 1017 seconds.
>
> --
> Shane Stanley <email@hidden>
> 'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
>
>
> _______________________________________________
> 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
_______________________________________________
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