Numbering lines
hh
hh at hyperhh.de
Sat Oct 27 14:53:31 EDT 2018
1. Besides removing scroll-update, which takes most of the time, you could
try the following array-methods (which are essentially from my stack
http://forums.livecode.com/viewtopic.php?p=101301#p101301 , see there
card "LineNums, tab "Nb2").
This needs here on a medium fast machine (Mac mini, 2.5GHz) in average
with LC 9.0.1 (which is at about 30% faster than LC 8.1.10 with that):
680 ms for 10000 lines to add the line numbers,
650 ms for 10000 lines to remove the line numbers,
both incl. the field update (a lot of long lines are to break).
-- Add "inline line numbers" [-hh fecit, 2014]
-- Uses separator ": " (In LC 6 use one single char, remove below needs that)
on mouseUp
lock screen; lock messages
put the millisecs into m1
set cursor to watch
put fld "IN" into T
split T by return
put the keys of T into K
sort K numeric
repeat for each line L in K
put cr & L & ": " & T[L] after S --> change separator here
end repeat
set text of fld "OUT" to char 2 to -1 of S
put -1+the num of lines of S & " lines: " & \
the millisecs -m1 & " ms" into fld "timing"
end mouseUp
-- Remove "inline line numbers" [-hh fecit, 2014]
-- Uses separator ": " (the above, in LC 6 you have to use one single char)
on mouseUp
lock screen; lock messages
put the millisecs into m1
set cursor to watch
put the text of fld "OUT" into S
split S by return and ": " --> change separator here
put the keys of S into K
sort K numeric
repeat for each line L in K
put cr & S[L] after T
end repeat
put char 2 to -1 of T into fld "IN2"
put -1+the num of lines of T & " lines: " & \
the millisecs -m1 & " ms : " & (fld "IN2" is fld "IN") into fld "timing"
end mouseUp
2. All "big" editors that show line numbers never update the whole long text
** but only a few lines more than the visible line range **. Using that, nearly
every LCS method (that locks the screen (and messages)) will be fast enough.
> JLG wrote:
> Another issue may be the line that updates the scrollbar. Try commenting out
> that line as a test just to see if that's the problem. If so, you might opt
> for a spinner or progress bar instead.
>
> > David Glasgow wrote:
> > your routine is about the same as mine - 3200 lines in 106 seconds (on my
> > fairly old MacBook).
> >> Mark Hsu wrote:
> >> <use-livecode at lists.runrev.com> wrote:
> >>
> >> I think your issue is where you say “put tcount & j into line tcount of it”
> >> — The line X of … call is very slow as it has to count every line from 1 - X.
> >> try this:
> >>
> >> local tBuffer
> >> put 1 into tCount
> >> repeat for each line j in pText
> >> put tCount & j & lf after tBuffer
> >> add 1 to tCount
> >> set the thumbpos of scrollbar “filterprog” to tCount
> >> end repeat
> >> delete line -1 of tBuffer
> >> put tBuffer into pText //If you want to update the initial variable with
> >> the numbered lines
> >> put tBuffer into field “numberedtext"
> >>> David V Glasgow wrote:
> >>>
> >>> Hello folks
> >>>
> >>> I am doing a content analysis of online chat and messaging. Sometimes very
> >>> large files, thousands or even hundreds of thousands of messages. I am
> >>> finding filter and find to be delightfully fast.
> >>>
> >>> However…. Sometimes I want to prefix each line with the line number, and do
> >>> this:
> >>>
> >>> put 1 into tcount
> >>> repeat for each line j in it
> >>> put tcount & j into line tcount of it
> >>> put tcount + 1 into tcount
> >>> set the thumbpos of scrollbar "filterprog" to tcount
> >>> end repeat
> >>> put it into field “numberedtext”
> >>>
> >>> I use ‘it’ because of a dim memory (superstition? Myth?) from long ago that
> >>> it is faster than an arbitrarily named variable. Still, the whole process
> >>> is pretty darned slow. Any brilliant suggestions?
More information about the use-livecode
mailing list