OMG text processing performance 6.7 - 9.5

hh hh at hyperhh.de
Mon Feb 3 15:19:18 EST 2020


Parse1 is here always at least 30% faster than Parse2.

Yet another approach in LC 7/8/9 that I find to be very
fast (especially for a lot of hits in large strings,
e.g. when searching for "and" or "the"):

-- Offset per ItemDelimiter
-- Searches for pStr in pSrc using pCase
function Parse0 pStr, pSrc, pCase
  set the caseSensitive to pCase
  set the itemDelimiter to pStr
  put the length of pStr into tN0
  put 1 into tN
  repeat for each item tI in pSrc
    add the length of tI to tN
    put tN & cr after tOut
    add tN0 to tN
  end repeat
  return line 1 to -2 of tOut
end Parse0

> Richard G. wrote:
> 
> -- Offset in place:
> function Parse1 pStr, pSrc
>    put 0 into tStart
>    repeat
>      put offset(pStr, pSrc, tStart) into tOS
>      if tOS = 0 then exit repeat
>      add tOS to tStart
>      put tStart &cr after tOut
>    end repeat
>    return tOut
> end Parse1
> 
> -- Delete as you go:
> function Parse2 pStr, pSrc
>    put 0 into tStart
>    repeat
>      put offset( pStr, pSrc) into tOS
>      if tOS = 0 then exit repeat
>      delete char 1 to tOS of pSrc
>      add tOS to tStart
>      put tStart &cr after tOut
>    end repeat
>    return tOut
> end Parse2




More information about the use-livecode mailing list