james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Noel J. Bergman" <n...@devtech.com>
Subject RE: String.equalsIgnoreCase Considered Evil :-)
Date Mon, 05 Aug 2002 20:06:33 GMT

I am running with JDK 1.4, which has String.java v1.150.  As the attached
program illustrates, using String.equalsIgnoreCase is faster than using
String.equals for the first command on the chain, about break-even for the
second, and generally slower for all other commands.

One reason for this is that String.toUpperCase is optimized.  In the normal
event that the SMTP client passes upper case commands across the wire,
String.toUpperCase simply returns the original string.

However, even in the case where the command is passed in lower case, the
result is simply shifted a couple of comparisons down the chain.  And since
we have not sorted the command chain by frequency of use, commands such as
DATA and RETR are slower with the original code.  When we get to handlers
such as IMAP which have a more extensive and active set of commands, the
impact will be even greater.  Oh, and there is also an impact based upon
command length, which is why TOP is faster with equalsIgnoreCase, even
though it is further down the chain.  On the other hand, longer IMAP
commands will be slower.

None of this is about big chunks of time, but the change was simple enough,
and is demonstrably faster.

	--- Noel

View raw message