Re: question on func equal_from
- Posted by Pete Lomax <petelomax at blueyonde?.c?.uk> Jul 27, 2007
- 690 views
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.