tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Caldarale, Charles R" <Chuck.Caldar...@unisys.com>
Subject RE: svn commit: r1417194 - in /tomcat/trunk/java/org/apache/tomcat/util/buf: ByteChunk.java CharChunk.java
Date Sat, 08 Dec 2012 02:40:05 GMT
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: svn commit: r1417194 - in /tomcat/trunk/java/org/apache/tomcat/util/buf:
ByteChunk.java CharChunk.java

> On 12/4/12 4:21 PM, markt@apache.org wrote:
> > +    private int hashCode=0;
> > +    // did we compute the hashcode ?
> > +    private boolean hasHashCode = false;

> Should hashCode and hasHashCode be volatile?

Yes, to insure program order is followed; otherwise there's no guarantee that hashCode and
hasHashCode are written in the required sequence.

> In fact, there seems to be much more code in there than necessary. Why not:

> > +    public int hashCode() {
> > +        if (hasHashCode) {
> > +            return hashCode;
> > +        }
> > +        hashCode = hash();
> > +        hasHashCode = true;
> > +        return hashCode;

Or:

    public int hashCode() {
        if (!hasHashCode) {
            hashCode = hash();
            hasHashCode = true;
        }
        return hashCode;
    }

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus
for use only by the intended recipient. If you received this in error, please contact the
sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message