- see footer for list info -<
What Russ is trying to say is that if you are using Strings as your
case indicators

eg:
<cfswitch expression="#myVar#>
<cfcase value="Simon">
<!--- do something --->
</cfcase>
<cfcase value="Baynes">
<!--- do something else --->
</cfcase>
</cfswitch>

Then it will be slower than replacing that with an if-elseif-else
equivalent. This is because in Java you cannot do the above as a
switch statement can only be against a numeric value. So ColdFusion
achieves this by trying it and if it throws a runtime exception it
then converts it to an if-elseif-else equivalent.

This may well explain why it gives a compile time error and does not
necessarily support your assumption that:-

"the fact that it doesn't permit a duplicate value tells me it is"

Regards,

Simon

On 8/7/06, Charlie Arehart <[EMAIL PROTECTED]> wrote:
>- see footer for list info -<
Snake, are you agreeing or disagreeing that a switch is faster than a series
of if/elseifs? I'm afraid I'd have to dust off my Assembler book from 23
years ago to try to understand what you were implying. :-)

My point was that under the covers the switch for cfcase value="value1",
cfcase value="value2", and cfcase value="value3,value4" would become, in
effect:

If value1, jump to case for value1
If value2, jump to case value2
If value3 or value4, jump to case

And because it's a jump to a specific case (or in some languages, a goto),
it would not ever evaluate any other of the cases. And when a given case is
found and done, it jumps to the end of the switch. Again, I don't know this
to be the case, but the fact that it doesn't permit a duplicate value tells
me it is.

Actually, that tells me it's creating instead an associative array that has
the smarts to not allow more than one element of a given name (the values in
the cases) and the value of each element is the case to jump to. Again,
maybe someone with more knowledge of internals of CFML can confirm the
specifics, but I would conclude from the inability to have a duplicate value
that it DOES NOT evaluate each case one by one. If it did that, it wouldn't
need to enforce uniqueness.

I'll certainly welcome hearing from anyone with internals knowledge. In
fact, I'll pass this along to some engineers at Adobe to see if they have a
thought.

/charlie
http://www.carehart.org/blog/

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Snake
Sent: Monday, August 07, 2006 12:58 PM
To: 'Coldfusion Development'
Subject: RE: [CF-Dev] CFSwitch... Aren't all cases evaluated?

>- see footer for list info -<
Even if you compile this down to machine code, it still essentially works
the same way, so a number of checks have to be performed in order.

E.G.


        LDA somevalue
        LDY #00
loop1   CMP casevalues,y
        BEQ case1
        INY
        CPY #10
        BNE loop1
        RTS
Case1   etc...
-
Russ



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Charlie Arehart
Sent: 07 August 2006 16:39
To: 'Coldfusion Development'
Subject: RE: [CF-Dev] CFSwitch... Aren't all cases evaluated?

>- see footer for list info -<
Well, "how else it could work" is the way that a true switch/case works in
other languages, where the whole point really is that all the switch/case
logic gets turned under the covers into a "computed goto", where once the
expression is determined, it "jumps" to the one (and only one) condition
that it could match. That's why it's always said to be faster than an
equivalent list of IF/ElseIF statements.

And in fact, I do believe that that IS the way CF works. Here's proof. Some
may know that CFCASE can list more than one value. That's handy. But it DOES
NOT open the door to permitting any of multiple cases to be matched. In the
following code:

<cfswitch expression="sam">
        <cfcase value="bob">
                I'm in bob
        </cfcase>
        <cfcase value="bob,sam">
                I'm in bob or sam
        </cfcase>
        <cfdefaultcase>
                I'm in neither case, the default
        </cfdefaultcase>
</cfswitch>

it errors complaining that "The CFSWITCH has a duplicate CFCASE for value
"BOB". That would indicate that indeed, it wants to know there is one and
only one case that could match. And the only reason to do that would be if
it intends to jump to that, and not do a scroll down the list of cases.

Maybe someone with more internals understanding can more categorically state
or prove that it doesn't go down the list of cases. I would think, though,
that the book reference JGG offers was simply a mistake on the author's part
(and there were multiple contributors, so it could have been other than
Ben). JGG, was that the 7 version, or the 6? I see no errata about this in
the 7 version (http://www.forta.com/books/errata.cfm?p=36). I don't see any
link to the older books, so can't check their errata. It could be that it
was caught and corrected in subsequent versions. What section and page (and
version) is that in? I have the 7 edition and can compare it, and report it
to Ben if it's indeed "fresh".

/charlie
http://www.carehart.org/blog/

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Snake
Sent: Monday, August 07, 2006 6:27 AM
To: [EMAIL PROTECTED]; 'Coldfusion Development'
Subject: RE: [CF-Dev] CFSwitch... Aren't all cases evaluated?

>- see footer for list info -<
Yes that is correct, all cases will be evaluated until a match is found, how
else could it work?

But here is a little nugget.
If you are evaluating strings in your cfcases, as you probably are 99% of
the time. CFIF/ELSE is faster.

Russ

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Terry Riley
Sent: 07 August 2006 11:15
To: [email protected]
Subject: Re: [CF-Dev] CFSwitch... Aren't all cases evaluated?

>- see footer for list info -<
----- Original Message -----

> *From:* "Jolly Green Giant" <[EMAIL PROTECTED]>
> *To:* [email protected]
> *Date:* Sun, 6 Aug 2006 23:07:50 -0400
>
> >- see footer for list info -<
> I'm studying for my certification.  Forta, in the study book, says
> that "like cfif, you should put the most popular cases at the top of
> the cfswitch block to improve performance.
>
> I thought one of the things was that all the cases were going to be
> evaluated anyway?  If they're all evaluated, then their location is no
> performance gain, right?

I don't think they are all evaluated, unless it goes to the default case
(which is usually last). IIRC, evaluation continues until a match is found.

There may be others out there that disagree....

HTH

Terry


_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<


_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<


_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help
>-<

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<



--
Simon Baynes
www.simonbaynes.com
_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
- Hosting provided by www.cfmxhosting.co.uk -<
- Forum provided by www.fusetalk.com -<
- DHTML Menus provided by www.APYCOM.com -<
- Lists hosted by www.Gradwell.com -<
- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to