in reply to Re: Re: Re: Duff's Device
in thread Duff's Device
Also, this causes a linear scan of your code, so your jump will be slower (in the worst case) if your code base is larger.That's just a bit misleading. If I didn't know how it really works, I'd take it to mean that it starts at the beginning of your program and scans the whole thing for the label. What it actually does is multiple linear scans from the innermost dynamic scope to the outermost dynamic scope. Since most gotos are local, the operation is usually relatively fast regardless of the code base size. But you did say "in the worst case", so I can't quibble about that. It's just the implication that there is only one linear scan of all the code.
And in fact, none of the individual scans are quite "linear" either. More like "cyclical". In a given dynamic scope, it always starts scanning forward first, and when it hits the end of the scope, it starts back at the beginning until it comes back to the place it started. Not only does this optimize for the fact that most gotos go forward rather than backward, but it also naturally cuts out of the loop any inner scope we already searched without an extra test.
That doesn't stop it from being bizarre though. And it will bite you hard if you misspell the label. Plus I don't know if Perl 6 will support goto EXPR, because it's a lot of hard work, and you have to be a crazy megalomaniac to do it. (I'd give examples of megalomaniacs, but I'm not exempt from Godwin's Law. Where do you apply for that?)
|
---|