Re: find_from and match_from
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 21, 2007
- 673 views
Matt Lewis wrote: > > 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: > }}} <eucode> > 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 > </eucode> {{{ > > 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] This is not conclusive. Although the IL says to create a slice and assign it to the temp, does the opcode RHS_SLICE actually allocate RAM for the subsequence and copy data to the new RAM, or does it just create a reference to the existing RAM? As the function never assigns to the slice, a reference is all it really needs. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell