james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harmeet Bedi" <harm...@kodemuse.com>
Subject Re: String.equalsIgnoreCase Considered Evil :-)
Date Mon, 05 Aug 2002 21:10:47 GMT
> string.equalsIgnoreCase(<literal>)
>
> This use is terribly inefficient.  Each and every call iterates through
both
> the string and the literal, uppercasing both as it compares them.

No only till there is a match. The conversion would cease if a character
does not match.


Alternatively
String command = command.toUpperCase()
command.equals(<somecmd>)

would always convert the character to upper case even if there the command
string does not have a single character common with <somecmd>

In most cases the character conversion will happen for only one character.
That should be enough to reject the comparison

I think it would be better to find hotspots by profiling. The code may look
inefficient but may be fine. There may be other place like MailImpl, Linear
processor etc. where optimization may yield very good results.

Harmeet
----- Original Message -----
From: "Noel J. Bergman" <noel@devtech.com>
To: "James-Dev Mailing List" <james-dev@jakarta.apache.org>
Sent: Saturday, August 03, 2002 8:58 PM
Subject: String.equalsIgnoreCase Considered Evil :-)


> There are many places in James where we have lengthy sets of comparisons
of
> an unknown string value to a known string value.  These are many of these
of
> the form:
>
> string.equalsIgnoreCase(<literal>)
>
> This use is terribly inefficient.  Each and every call iterates through
both
> the string and the literal, uppercasing both as it compares them.
>
> Please, as you are working on code (Peter will apply these to POP3Handler
> and SMTPHandler), if you see this pattern, please change it to:
>
> string = string.to[Upper|Lower]Case();  // chose depending upon your
> literals
>
> string.equals(<literal>)
>
> For example, in SMTPHandler and POP3Handler:
>
>       String command = commandRaw.trim();
>  becomes
> String command = commandRaw.trim().toUpperCase();
>
> and the test for "USER" (for example) becomes:
>
>         if (command.equals("USER")) ...
>
> Actually, I believe that we should add a command-map model to the
handlers,
> but that's a seperate issue for a separate thread.  The change proposed in
> this e-mail is simple.
>
> --- Noel
>
> P.S.  Brownie points for whomever recognizes the origin of the subject
> header
>
>
> --
> To unsubscribe, e-mail:
<mailto:james-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:james-dev-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:james-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:james-dev-help@jakarta.apache.org>


Mime
View raw message