cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefano Mazzocchi <stef...@apache.org>
Subject Re: another fix for HEAD?
Date Thu, 08 Jun 2000 11:54:57 GMT
Donald Ball wrote:
> 
> On Wed, 7 Jun 2000, Jeremy Quinn wrote:
> 
> > Dear All,
> >
> > In what may constitute my first bug patch :)
> >
> > May I most humbly propose that the following change is made to Engine.java.
> >
> > Change (line 369)
> >
> > // if verbose mode is on the the output type allows it
> > // print some processing info as a comment
> > if (VERBOSE && (page.isText())) {
> >       time = System.currentTimeMillis() - time;
> >       out.println("<!-- This page was served "
> >               + (page.isCached() ? "from cache " : "")
> >               + "in " + time + " milliseconds by "
> >     + Cocoon.version() + " -->");
> > }
> >
> > to
> >
> > if (VERBOSE && (page.isText()) && (request.getMethod() != "HEAD"))
{
> >       time = System.currentTimeMillis() - time;
> >       out.println("<!-- This page was served "
> >               + (page.isCached() ? "from cache " : "")
> >               + "in " + time + " milliseconds by "
> >     + Cocoon.version() + " -->");
> > }
> >
> > This probably is not right, but it shows what I think needs to happen.
> 
> Looks good to me, except for the fact that
> 
> String != String
> 
> is not correct, you need to do
> 
> !String.equals(String)

To be precise (and maybe help some of you with non-so-evident java
features):

 if (request.getMethod() != "HEAD")

would work just fine if the string returned by that method is _exactly_
the same object that the "HEAD" string is in your JVM. This method is
very fast because compares memory locations and it's normally done to
optimize if you have control on everything that happens in your code
(unlike this case where the string is generated by the servlet engine)

 if (request.getMethod().equals("HEAD"))

works every time the first string is equal to the second one, and this
is done by comparing the single chars one by one until the whole string
is checked. Note this is normally implemented natively inside the JVM to
speed up or hotspot JVM can optimize this very fast since string
handling is almost always an hotspot.

Note the above may result in a nullpointerexception if the returned
string is null, so the best way to do this is

 if ("HEAD".equals(request.getMethod()))

even if not so evident at first.

Hope this helps.

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<stefano@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------
 Missed us in Orlando? Make it up with ApacheCON Europe in London!
------------------------- http://ApacheCon.Com ---------------------



Mime
View raw message