-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> > <CFIF NOT Len(Trim(Form.firstname))> doesn't work
> >
> > whereas <CFIF Len(Trim(Form.firstname)) GT 0> does work.
> >
> > Why?
> >
> > best,  paul
> 
> Try
> <CFIF Trim(Form.firstname) IS NOT "">
> "" is a sort of short-hand for string NULLs. It means "empty
> string".  
> 
> True
> <CFIF Len(Trim(Form.firstname)) GT 0>
> will work, however it should be slower than the other. Why? The
> first theoretically only has to test the first character (is it 
> NULL or not?). The
> one with len has to run through and count all the characters 
> in the string.
> 
> I've never actually timed it in CF, mind you. But I've built string
> functions in assembly before, and unless the Allaire programmer
> really messed up their code, the first will always be faster,
> though 
> a bit more
> cryptic :)


You've got that backwards there.  The Len(whatever) method is 2 to 3
times faster than the whatever IS "" method.  Here's why:
(If you don't know at least a little C/C++, this may go over your
head.  My apologies.)

ColdFusion uses either BSTRs or MFC CStrings (which are implemented
as BSTRs, I believe) instead of the usual C/C++ NULL terminated
strings.

BSTRs are counted NULL terminated strings, that is the 4 bytes before
the actual string data are an integer that contain the length of the
string.  In order to do the "Len(whatever)" calculation, CF needs
only look at the length integer & do an integer comparison with
whatever number you want (an implied 0 in this case).  To do the
"whatever IS NOT ''" thing, CF has to actually do a string comparison
(dereference the pointers to the first characters of each string,
compare those, move to the next, do it again, etc.).  Even if both
strings are empty (""), that's at least two extra comparisons.

So definitely, use the cryptic Len(whatever) version, especially if
you're in any kind of a loop.

Best regards,
Zac Bedell

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 6.5.2 for non-commercial use <http://www.pgp.com>
Comment: Please use PGP!!!

iQA/AwUBOVi+DwraVoMWBwRBEQLZiACggGMDCZ83E0363CR84QH5vW0V9U4An3cX
vwPGlG+/LyaVqXLfWoMb4sF9
=2Po/
-----END PGP SIGNATURE-----
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to