My Bold Script is slow
iansummerfield at btconnect.com
Sun Feb 3 09:14:01 CST 2002
I can see two major problems. The first is you change the textStyle of
each and every character selected regardless of whether it needs it or not,
but you only really need to do that if the style was in that character in
the first place. This speeds it up a lot.
The second is probably harder to measure, but each time round your loop the
cpu will need to recalculate your loop "from" and "to" functions, so it's
much better programming to put the calculations before the loop and have
them calculate just the once. See my variables "StartLoop" and "EndLoop".
Another minor thing is to use lockscreen to prevent the screen redrawing too
I didn't like your two replaces, I can see why you need them but you might
like to experiment with my alternate method of using a sort. I just
replace "bold" in a string like "underline,italic,bold" to leave:
"underline,italic,", I then sort by item and get ",italic,underline" and
can delete the first comma. I don't know it's any faster, you'll have to
experiment. By seeing the tick count anyway it'll be easy to tell which is
I added in some timing stuff, so I can tell what speed it's running at. My
tests saw your original script go from 77 ticks to 19 in my revised one,
but it depends on how large your selectedchunk is and how my characters are
put the ticks into starttime
put "bold" into myStyle
put (the second word of the selectedChunk) into loopStart
put (the fourth word of the selectedChunk) into loopEnd
set lockscreen to true
set cursor to watch
repeat with myChar = loopStart to loopEnd
put the textStyle of char myChar of card field "text" into myRepeat
if myStyle is in myRepeat then
replace myStyle with "" in myRepeat
sort items of myRepeat -- there'll be an empty item
delete char 1 of myRepeat -- it's a comma for the empty item
set the textstyle of char myChar of card field "text" to myRepeat
set lockscreen to false
put the ticks-starttime
On 2/2/02 11:09 pm, "Björnke von Gierke" <bvg at mac.com> scribed:
> Well, my bold Script is really slow, and I would appreciate any input
> for making it faster. Concrete are the loops at the bottom the problem,
> but I don't know an other way to change the bold, but leave other styles
> alone, as the forever-be-damned-and-burn-in-hell "textstyle" property is
> set to the uglier-as-my-dogs-ass "mixed" state.
> here it comes, please be aware, that any brain injures caused by this
> script are the brain owners problem:
> on mouseUp
> repeat with myChar = the second word of the selectedChunk to the
> fourth word of the selectedChunk
> put the textStyle of char myChar of field "text" into myRepeat
> replace myStyle & "," with "" in myRepeat
> replace myStyle with "" in myRepeat
> set the textstyle of char myChar of field "text" to myRepeat
> end repeat
> end mouseUp
> I tried the "for each char" loop, but it was not applicable the way i
> used it. (it provided always the character, but no number or other
> location possibility)
> for better reading copy to a button and tab on each line.
> for use set the traversalon to false
> hope you find something faster...
> use-revolution mailing list
> use-revolution at lists.runrev.com
Macintosh Consultant - Hastings UK
This E-mail is from Ian Summerfield's home system.
The contents and any attachments to it include information that is
private and confidential and should only be read by those persons to
whom they are addressed. Ian accepts no liability for any loss
or damage suffered by any person arising from the use of this e-mail.
Ian does not accept any responsibility for viruses and it is your
responsibility to check the email and attachments (if any).
If you have received this e-mail in error, please destroy and delete
the message from your computer.
More information about the use-livecode