|
-
Assign function to variable (for speed)
hi Flash gurus!
I've read in various places that it is faster to assign a function to a variable
e.g var mround:Function = Math.round()
But I dont understand how that can be faster. Doesn't it still have to look up Math.round() when mround is called or does it copy the code from Math.round() into 'mround'?
I've accepted that it's faster - I just want to know why.
-
Hype over content...
Your syntax is slightly out, should be
var mround:Function = Math.round;
It's quicker because mround is a pointer to the method, it doesn't have the overhead of having to find the Math class, and then finding the round method within that class, it points to it directly.
So it doesn't copy code, it's just a short cut ( Via a pointer ). It's the same way as this is quicker
var mc:MovieClip=_root.child1.child2.child3;
mc._x=100;
over,
_root.child1.child2.child3._x=100;
Squize.
-
Cool. Thanks for the explaination
-
Zombie Coder
Hmm.didn't know that. Cheers Squize
-
Hype over content...
np guys. If either of you can face trawling through a fair bit of spam, there are lots of handy little tips like this in the optimisation thread ( via the knowledge base sticky ).
Squize
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|