This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: String hashCode


Per Bothner wrote:

> It might also be useful to have a way to quickly determine if a
> String is interned.  This could be done by determining that
> this.data==data and boffset has a magic value - perhaps
> just enough to leave room for a hashCode before the String proper.

Except that Strings where this.data != data can still be interned, for
example "sub = str.substring(5,10); sub = sub.intern()", right? I suppose
intern() could simply copy the string value in this case.

I'd prefer to simply add a hashcode field, but only set it if hashcode() is
called or the string gets interned. But, as you point out, there is the
problem of how to determine whether the value has been set or not.

It would seem reasonable to set it to null or some other unlikely value
initially, then bump it if the string just happens to hash to the same value
- but this would violate the published spec of String.hashCode.

regards

  [ bryce ]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]