Re: even better coerce to record with usrf
Re: even better coerce to record with usrf
- Subject: Re: even better coerce to record with usrf
- From: Arthur J Knapp <email@hidden>
- Date: Fri, 14 Dec 2001 19:18:27 -0500
>
Subject: Re: even better coerce to record with usrf
>
From: email@hidden (Michael Sullivan)
>
Date: Fri, 14 Dec 2001 17:08:56 -0500
>
> Exciting applications for this include: saving records and multi-level
>
> lists as text files (more economical than saving them as scripts),
I hadn't thought about that. I'll have to do some file-size tests...
>
> Arthur's lightning fast string-to-ascii and string-to-hex converters, and
>
> the current discussion about using strings to access record labels.
>
The unfortunate thing about this is that Arthur's string to ascii and
>
ascii to string mods are *not* faster than using the standard additions
>
osax on single character strings. They break even around 4-5 characters
>
and then get much faster after that.
The method was only designed for speeding up large string conversions.
In a situation where I needed a fast way to *repeatedly* convert numbers
into *single* character strings, I would probably just use a hard-coded
string of all the characters:
property kBytes256 : run script "
set characterList to {}
repeat with x from 0 to 255
set end of characterList to ASCII character x
end
characterList"
on AsciiCharacter(n)
return item (n + 1) of kBytes256
end AsciiCharacter
The reverse situation, where you needed to repeatedly coerce single
characters into integers, has no immediate solution that is faster
than the "ASCII number" command.
Or does it... ;-) ;-) ;-)
property kUsrfLongHeader : ({{a:0}} as string)'s text 1 thru -2
on AsciiNumber(c)
return a of ((kUsrfLongHeader & c) as record)
end AsciiNumber
on AsciiCharacter(n)
return ({{a:n}} as string)'s item -1
end AsciiCharacter
set t0 to current date
repeat 1000 times
ASCII number "a"
end repeat
set t1 to current date
repeat 1000 times
AsciiNumber("a")
end repeat
set t2 to current date
{t1 - t0, t2 - t1} --> {21, 1}
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.lazerware.com/>
on error number -128
end try
}