Re: 2.6 feature request: sameRef()
- Posted by Robert Craig <rds at RapidEuphoria.com> Jul 07, 2005
- 660 views
Pete Lomax wrote: > The background processing in Edita now goes something like this: > > }}} <eucode> > for i=1 to length(filetext) do > text=filetext[i] > bGpathname={filepaths[i],filenames[i]} > Scan() > for j=1 to length(filetext) do > if equal(bGpathname,{filepaths[j],filenames[j]}) then > if equal(text,filetext[j]) then > routines[j]=Results > end if > exit > end if > end for > <font color="#330033"></eucode> {{{ </font> > > (The j loop covers the case whereby the file has been moved in the > list, be that because it or one earlier in the list has been closed, > or Ctrl Page Up/Down has changed the file order, between the start and > exit of the Scan() operation, which can take several seconds). > > The line: > if equal(text,filetext[j]) then > > actually only cares whether they are still the same reference. If I > had a sameRef() function, I wouldn't need bGpathname at all, plus of > course it would be an instant check rather than a possibly lengthy > compare. That also means I could perform the check inside Scan(), to > quit early if the file has been modified, whereas comparing a 35,000 > line win32lib 35,000 times is perhaps not such a good idea. > > I don't believe there is any way I could try this in eu.ex? eu.ex doesn't know anything about reference counts, and doesn't need to, since it's written in Euphoria. I'd be very reluctant to make reference counts, or the sharing of data visible in the language spec. But let me assure you that if you perform: equal(x,y) and x and y internally point to the same sequence in memory, Euphoria will instantly know they are equal, just by comparing the pointers. So for example, if you had: text = filetext[i] where filetext[i] was a one million character string, and later you said: if equal(text, filetext[i]) then ... Euphoria would not compare one million characters. It would instantly "see" that text and filetext[i] were pointing to the same place in memory, and were therefore the same sequence. I don't do this for compare() however. I considered it, but concluded it was less common that you'd compare() things that are the identical sequence in memory. Usually it would be different sequences in memory that happen to have the same value. I could be wrong, but the examples I looked at seemed to confirm this. I hope that helped. I didn't fully understand what you are trying to accomplish. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com