On Thu, Jan 7, 2016 at 10:54 PM, Josh Tynjala <joshtynj...@gmail.com> wrote:
> That's odd. I swear I remember someone from Adobe once explaining that > function-style casting is faster than as-style casting (with the exception > of primitive types that have a top level function that makes function-style > casting impossible, as you mentioned in 1). I've tried to avoid as-style > casting for years, based on this knowledge. > > - Josh > See this stack overflow answer and the articles it links: http://stackoverflow.com/a/14268394 *EDIT:* concerning performance, using as is reported to be faster than the > function call style casting in various articles: [1 > <http://jacksondunstan.com/articles/830>] [2 > <http://upshots.org/actionscript/20-tips-to-optimize-your-actionscript>] [ > 3 > <http://gamedevjuice.wordpress.com/2008/02/15/seven-tips-about-performance-optimization-in-actionscript-3/>]. > The first article cited looks at the performance differences in depth and > reports that as is 4x-4.5x faster. > > *EDIT 2:* Not only is as 4x-4.5x faster in the normal best case, but when > you wrap the (cast) style conversion in a try-catch block, and an error > actually ends up being thrown, it's more like 30x - 230x faster. In AS3, if > you think you're going to do something exceptional (in that it could throw > an error) then it's clear that you should always look before you leap. > Never use try/catch unless forced to by the API, and indeed that means to > never (cast) It also is instructive to look at the performance > implications of try/catch even when no exception is thrown. There's a > performance penalty to setting up a try/catch block even in the happy case > that nothing goes wrong. > >