You can measure the difference.  It is essentially function call overhead.  See 
http://blogs.adobe.com/aharui/2007/10/actionscript_readwrite_perform_1.html

So, over a million fetches you'll save by using _myVar, but consider that if 
someone subclasses and overrides, _myVar may not be what you want.

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Josh 
McDonald
Sent: Tuesday, December 02, 2008 1:49 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] any overhead for calling simple getters?


There's *some* overhead, but properties are part of the VM, so it's not going 
to be much.

Also, keep in mind, anything that's [Bindable] without [Bindable("eventName")] 
is going to have a get/set pair generated by MXMLC, even if you've already 
written a get/set pair.

Personally, I only ever use the _privateVar reference internally when there's 
some voodoo in the getter (like construction logic for first access, or 
something) I need to work around in some circumstances.

-Josh
On Wed, Dec 3, 2008 at 7:37 AM, Pan Troglodytes <[EMAIL 
PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:
If I have this:

private var _myvar:int;
public function get myvar():int
{
  return _myvar;
}

should I try to refer to it in other parts of the same class as _myvar, or is 
myvar equally efficient?  In Delphi, you can define a property like:

FMyVar: Integer;
property MyVar:Integer read FMyVar;

and all references to MyVar automatically get optimized to FMyVar.  But I'm 
wondering if Flex optimizes out the unnecessary function call represented above.

--
Jason




--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Like the cut of my jib? Check out my Flex blog!

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>
:: http://flex.joshmcdonald.info/
:: http://twitter.com/sophistifunk

Reply via email to