tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: svn commit: r1417194 - in /tomcat/trunk/java/org/apache/tomcat/util/buf: ByteChunk.java CharChunk.java
Date Fri, 07 Dec 2012 22:03:51 GMT
Mark,

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?

>      // -------------------- Hash code  --------------------
>  
> +    @Override
> +    public int hashCode() {
> +        if (hasHashCode) {
> +            return hashCode;
> +        }
> +        int code = 0;
> +
> +        code = hash();
> +        hashCode = code;
> +        hasHashCode = true;
> +        return code;
> +    }

Any particular reason for the dead store of 0 to 'code' local?

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;

-chris


Mime
View raw message