Well now,

This is most odd...

Using the very unscientific method below it looks like isDefined() is
actually faster than structKeyExists() at least half the time, or if there
is any difference between them it is far outweighed by other considerations.

<cfset time = getTickCount()>
<cfloop from="1" to="10000" index="i">
<cfset structKeyExists(variables,'varname1') />
</cfloop>

<cfoutput>structKeyExists(): #getTickCount() - time# <br /></cfoutput>

<cfset time = getTickCount()>

<cfset time = getTickCount()>
<cfloop from="1" to="10000" index="i">
<cfset isDefined('variables.varname2') />
</cfloop>

<cfoutput>isDefined(): #getTickCount() - time# <br /></cfoutput>

This is not at all what I would have expected given that the variable
doesn't exist in either case and that isDefined() is supposedly doing a
lookup of every scope.

Spike

--------------------------------------------
Stephen Milligan
Code poet for hire
http://www.spike.org.uk

Do you cfeclipse? http://cfeclipse.tigris.org


>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] On Behalf Of Barney Boisvert
>Sent: Monday, July 12, 2004 3:01 PM
>To: CF-Talk
>Subject: RE: StructKeyExists() vs IsDefined()
>
>That "glitch" is only relevant if you specify a scope name for
>the first
>argument of structKeyExists.  So the functional difference will only be
>there if you name a structure with a scope name.  The fact
>that the var is
>empty is only because that's what I assigned it to initially.  You can
>change it to something else and the functionality won't change.
>
>The point I was making was simply that isDefined does a lot
>more work, even
>for seemingly simple lookups.
>
>Cheers,
>barneyb
>
>> -----Original Message-----
>> From: Matt Robertson [mailto:[EMAIL PROTECTED]
>> Sent: Monday, July 12, 2004 3:51 PM
>> To: CF-Talk
>> Subject: Re: StructKeyExists() vs IsDefined()
>>
>> Barney Boisvert wrote:
>> > <cfset variables.variables.test = "" />
>> > <cfoutput>
>> > #isDefined("variables.test")#<br />
>> > #structKeyExists(variables, "test")#
>> > </cfoutput>
>> >
>> > isDefined() returns true, structKeyExists() returns false.
>>
>> So an empty value in a defined var comes up as nonexistent.  
>Yours and
>> Sean's points are well taken insofar as the efficiency of one vs. the
>> other are concerned, but this behavior is inconsistent with
>the avowed
>> purpose of the function.
>>
>> Add this to the bottom of your code:
>>
>> <cfdump var="#variables#" label="local scope">
>>
>> You'll see that the struct is there, and the key exists.  Its just
>> empty, which to me is nto the same condition as nonexistent.
> The docs
>> fail to mention this quirk, but they do say it is
>"sometimes" a usable
>> substitute for isdefined.  Too bad thats where the specifics end.
>>
>> You would have to build an app with this difference in behavior in
>> mind.  You couldn't just substitute one for the other to gain a speed
>> improvement, which is a bummer.
>>
>> --
>
>
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to