Re: question on func equal_from

new topic     » goto parent     » topic index » view thread      » older message » newer message

Salix wrote:
> So, my question remains. Why don't we have equal_from if speed 
> was such an important issue in case of find_from and match_from?

One of the reasons why find_from and match_from were needed is that the only way
to get at the fast scan code is to pass a slice. But an equal_from does not do a
scan, nor do you need to create a slice. You can instead code:
function match_at(sequence x, sequence s, integer pos)
    if not length(x) then ?9/0 end if
    if length(s)<pos+length(x)-1 then return false end if
    for i=1 to length(x) do
        if not equal(s[pos],x[i]) then return false end if
        pos+=1
    end for
    return true
end function


Now I do not know what the actual gain might be were that coded in the back-end,
but it would be small, not the 100-fold gain I am fairly confident I could show
with either match_from or find_from.

HTH,
Pete
Ps it is not quite the same as r=(match(x,s)=i) in cases where match finds an
instance of x earlier on in s, eg match_at("the", "the the", 4) should yield true
but r would be false since 1<>4.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu