Re: find_from and match_from

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

Derek Parnell wrote:
> Robert Craig wrote:
> > 
> > However, even today, there are cases where a slice does
> > not result in a new sequence being written. e.g.
> > 
> >    x = x[a..b]
> > 
> > will usually result in a simple update to the header
> > of sequence x, to show that it starts later, or ends
> > earlier (or both) in memory.
> 
> Ok. So something like this might be a tad faster ...
> 
> }}}
<eucode>
> function find_from_to(integer N, integer L, object a, sequence b)
>      b = b[N .. L]
>      L=find(a,b)
>      if L then
>        L += N-1
>      end if
>      return L
> end function
> </eucode>
{{{


The optimization only works when there is a single 
reference count on the sequence being sliced.

In the above case, the sequence referred to by b will have
two references on it, one from b, and one from the caller's
variable that is being passed in, so it will still be 
necessary to copy the elements N..L and create
a new sequence.

Here's an example of something that *would* be optimized:
    x = gets(f)
    if sequence(x) then
        x = x[1..$-1] -- drop new-line character
    end if 

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu