From: Charles Yeomans <[EMAIL PROTECTED]>
Date: Tue, 5 Sep 2006 15:20:45 -0400
Since you're solving a slightly different problem, your claim may be
tautologically correct for now.
Really? Damn I should have read closer. I thought we were trying to
turn multiple spaces into a single space, which would make sense for
processing HTML.
Well, this modified version should work better then. Why should mine
be faster?
* Mine processes each byte only once.
* That MySqueeze version processes each byte multiple times. There is
a loop for each char in the charset. An embedded loop for replacing
two chars with one, multiple times. And yet another embedded loop
within replaceallB (although you don't see that one.)
So that is 3 levels of loops, while mine only has 1. Something like
N^3 time vs my N time.
Once again, it can be called like this:
EditField1.text = Squeeze( EditField1.text, EditField2.text )
It can take and return strings, using operator convert.
There is some additional overhead however, in the creation of the
ElfDataCharSet. ElfDataCharSet is just a table of 256 booleans.
Overhead shouldn't be noticable for most purposes, and is
eliminatable if you were to pass an ElfDataCharSet directly instead
of relying on operator_convert from a string.
Function Squeeze(e as ElfData, CS as ElfDataCharSet) As ElfData
dim Found, CharNum, LastOut as Integer
dim fs as FastString
Found = e.InCharSet( CS )
do until Found = 0
CharNum = e.ByteVal( Found )
if e.ByteVal( Found + 1 ) = CharNum then
if fs = nil then fs = new FastString
fs.AppendSectElfData e, LastOut + 1, Found - LastOut
// find last byte in current run
while e.ByteVal( Found + 1 ) = CharNum
Found = Found + 1
wend
LastOut = Found
end if
Found = e.InCharSet( Found + 1, CS )
loop
if fs <> nil then
fs.AppendSectElfData e, LastOut + 1, ElfData.kEnd
Return fs
end if
Return e
End Function
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>