How to optimise out FindLink() from Eachin loop?

BlitzMax Forums/BlitzMax Programming/How to optimise out FindLink() from Eachin loop?

Beaker(Posted 2005) [#1]
For b:blah = EachIn blahlist
	bLink:TLink = blahlist.FindLink(b)
Next

Is there anyway to get rid of the FindLink()? Hacking into EachIn maybe to get the current TLink object?


Dreamora(Posted 2005) [#2]
Use the TListEnumerator

This way you can iterate through the TLink construction instead iterating through the values


Beaker(Posted 2005) [#3]
I'll just have to use a While loop instead. Easy answer.


Bot Builder(Posted 2005) [#4]
Type List Extends TList
	Field Enum:TListEnum

	Method ObjectEnumerator:TListEnum()
		enum=New TListEnum
		enum._link=_head._succ
		Return enum
	End Method

	Method CurrentLink:TLink()
		Return enum._link._pred
	End Method
End Type


;)

I'd leave it at using it for reading data, not modifying _pred/ _succ handles. I've tried. it didn't work very well. I wrote my own different style list:



Enum is public, so just access Enum.Current.


Beaker(Posted 2005) [#5]
Thanks bot. That works nicely.