As a followup to my article on Inlining Math.ceil(), I decided to inline some more functions in the Math class. Read on for the code as well as tests proving correctness and speed.
Posts Tagged functions
Getters and setters are indeed a very nice feature of AS3. They eliminate a lot of typing (.x versus .getX()) shaves off five characters and removes the need to hit the shift key for X) and make getting and setting values much more natural by disguising the fact that you’re actually calling a function. The downsides include the difficulty (impossibility?) of getting a Function variable for them and lower performance. This article is about that performance hit. EDIT: added a plain getter test)
With access specifiers, statics, plain functions, and overriding, there are a lot of ways you can dress up a function in AS3. But how many programmers really know the performance implications of these options? Read on to find a straightforward test showing just that. EDIT: added functions defined in interfaces, getters, setters, and final functions.
Regular expressions are downright handy for a variety of string processing tasks. They are so handy that they are built straight in to the language in the form of the /regexpgoeshere/ syntax. Well, usually…
In the midst of discussing my runnables technique for implementing function pointers over on the Rausch Generator Blog, I commented about the usefulness of the currying technique, mostly in callbacks. It occurred to me that I’ve been using a tiny helper class to curry functions for years in both AS2 and AS3, but that many people may have never stopped to write such a basic (in my opinion) class. So I figured I might as well re-implement the class and post it here.
One lovely trick C/C++ programmers can use is to replace conditional logic (eg. if statements) with function pointers if the result of the conditional logic is a loop invariant. Function pointers do exist in AS3 in the form of the Function class, but they are a dynamic class whose usage is very slow. AS3 also supports Namespaces, which can be used as a function pointer substitute. Are they any faster than directly using Functions? Read on for a quick test.
Adding on to existing arrays and vectors is one of those really common tasks that sounds dreary. Everyone knows about push() and unshift() for single elements and concat() for lots of elements. But what if you want to add a lot of elements to an existing array or vector without allocating a new array or vector? I have the solution.