On Sat, Aug 03, 2013 at 02:34:51PM -0700, Jonathan M Davis wrote: > On Saturday, August 03, 2013 14:25:24 H. S. Teoh wrote: > > On Sat, Aug 03, 2013 at 01:33:44PM -0700, Jonathan M Davis wrote: [...] > > > I definitely use scope from time to time, but I don't know how > > > frequently I use it in comparison to how often I should use it. I > > > was actually using scope(success) more until someone pointed out > > > that there's an efficiency hit with that as it was putting > > > try-catch blocks in places where there wouldn't have been before > > > (as opposed to scope(exit) or scope(failure) where you'd be using > > > try-catch blocks if you weren't using scope). > > > > [...] > > > > Hmm, I never thought of that. So that limits the use cases of scope > > guards even more. :-P > > Yeah. For instance, I'd made it so that RedBlackTree was using > scope(success) for mutating its length in a few places, which helped > make the code cleaner (because you didn't have to worry about > incrementing the length at each of the various return statements), but > that introduced try-catch blocks where there otherwise wouldn't have > been any, and that code definitely needs to be as efficient as > possible, so the scope(success) statements were removed from there. > Other code wouldn't care as much, but for something like RedBlackTree, > it really matters. It is a bit of a shame though, since it made the > code cleaner. [...]
On second thoughts, why is scope(success) implemented as try/catch? Shouldn't the compiler be able to insert it before the end of each block instead? Stack-unwinding bypasses the end of block code, so the only way you can get there is by successful exit. T -- Error: Keyboard not attached. Press F1 to continue. -- Yoon Ha Lee, CONLANG