Using Self as a Method Default

BlitzMax Forums/BlitzMax Programming/Using Self as a Method Default

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's something that's weird.

The fastest method gets 57 fps (in a 1 million cycle loop with Flip 0).

If I do it this way (notice the 'this' field):
Type TVector3
     Field x:Double, y:Double, z:Double
     Field this:TVector3

     Function Create:TVector3(x:Double = 0, y:Double = 0, z:Double = 0)
          Local v:TVector3 = New TVector3
          v.this = v
          v.x = x
          v.y = y
          v.z = z
          Return v
     End Function

     Method Add(a:TVector3, b:TVector3 = Null)
          If b = Null Then b = self.this
          self.x = b.x + a.x
          self.y = b.y + a.y
          self.z = b.z + a.z
     End Method
End Type

I get 56 fps which isn't a bad hit at all and lets me write it both ways of v1.add( v2 ) and v1.add( v2, v3). For some reason, setting b to a field that's holding the type is faster than just setting b to self. /shrug