Re: find_from and match_from
- Posted by Matt Lewis <matthewwalkerlewis at gmail.com> Mar 21, 2007
- 696 views
Derek Parnell wrote: > > Robert Craig wrote: > > the current match() and find() > > Robert, I vaguely remember someone saying that a slice doesn't create a new > sequence until such time as the slice is actually written to. Is that true? Not true. I disassembled Igor's example:
function find_from_to(integer N, integer L, object a, sequence b) L=find(a,b[N .. L]) if L then return L-1+N else return L end if end function
Notice line 7, where the slice is created an assigned to the temp. An additional slow down occurs here through the arithmetic to convert from the slice to the sequence as a whole. SubProgram [find_from_to:00116] 1: 096 117 # INTEGER_CHECK: [N:117] 3: 096 118 # INTEGER_CHECK: [L:118] 5: 097 120 # SEQUENCE_CHECK: [b:120] 7: 046 120 117 118 121 # RHS_SLICE: [b:120] [N:117]..[L:118] => [_temp_:121] 12: 077 119 121 118 # FIND: [a:119], [_temp_:121] => [L:118] 16: 020 118 32 # IF: [L:118] = 0 goto 0032 19: 010 118 122 121 # MINUS: [L:118], [LIT 1:122] => [_temp_:121] 23: 011 121 117 121 # PLUS: [_temp_:121], [N:117] => [_temp_:121] 27: 028 116 121 # RETURNF: [_temp_:121] 30: 023 35 # ELSE goto 0035 32: 028 116 118 # RETURNF: [L:118] 35: 043 # BADRETURNF: End SubProgram [find_from_to:00116] Matt