Commit b5349c07 by Bryce McKinlay Committed by Bryce McKinlay

Locale.java (hashcode): Made transient.

	* java/util/Locale.java (hashcode): Made transient.
	(hashCode): No longer synchronized.
	(equals): Remove comment.
	(writeObject): No longer synchronized. Implement using writeObject
	calls instead of tweaking hashCode field. Update doc.
	(readObject): Implement using readObject calls.

From-SVN: r84027
parent bdee7684
2004-07-02 Bryce McKinlay <mckinlay@redhat.com>
* java/util/Locale.java (hashcode): Made transient.
(hashCode): No longer synchronized.
(equals): Remove comment.
(writeObject): No longer synchronized. Implement using writeObject
calls instead of tweaking hashCode field. Update doc.
(readObject): Implement using readObject calls.
2004-06-26 Geoffrey Keating <geoffk@apple.com> 2004-06-26 Geoffrey Keating <geoffk@apple.com>
Andreas Tobler <a.tobler@schweiz.ch> Andreas Tobler <a.tobler@schweiz.ch>
......
...@@ -186,7 +186,7 @@ public final class Locale implements Serializable, Cloneable ...@@ -186,7 +186,7 @@ public final class Locale implements Serializable, Cloneable
* *
* @serial should be -1 in serial streams * @serial should be -1 in serial streams
*/ */
private int hashcode; private transient int hashcode;
/** /**
* The default locale. Except for during bootstrapping, this should never be * The default locale. Except for during bootstrapping, this should never be
...@@ -709,10 +709,8 @@ public final class Locale implements Serializable, Cloneable ...@@ -709,10 +709,8 @@ public final class Locale implements Serializable, Cloneable
* *
* @return the hashcode * @return the hashcode
*/ */
public synchronized int hashCode() public int hashCode()
{ {
// This method is synchronized because writeObject() might reset
// the hashcode.
return hashcode; return hashcode;
} }
...@@ -731,10 +729,6 @@ public final class Locale implements Serializable, Cloneable ...@@ -731,10 +729,6 @@ public final class Locale implements Serializable, Cloneable
return false; return false;
Locale l = (Locale) obj; Locale l = (Locale) obj;
// ??? We might also want to add:
// hashCode() == l.hashCode()
// But this is a synchronized method. Is the overhead worth it?
// Measure this to make a decision.
return (language == l.language return (language == l.language
&& country == l.country && country == l.country
&& variant == l.variant); && variant == l.variant);
...@@ -745,17 +739,19 @@ public final class Locale implements Serializable, Cloneable ...@@ -745,17 +739,19 @@ public final class Locale implements Serializable, Cloneable
* *
* @param output the stream to write to * @param output the stream to write to
* @throws IOException if the write fails * @throws IOException if the write fails
* @serialData the hashcode should always be written as -1, and recomputed * @serialData The first three fields are Strings representing language,
* when reading it back * country, and variant. The fourth field is a placeholder for
* the cached hashcode, but this is always written as -1, and
* recomputed when reading it back.
*/ */
private synchronized void writeObject(ObjectOutputStream output) private void writeObject(ObjectOutputStream s)
throws IOException throws IOException
{ {
// Synchronized so that hashCode() doesn't get wrong value. s.writeObject(language);
int tmpHashcode = hashcode; s.writeObject(country);
hashcode = -1; s.writeObject(variant);
output.defaultWriteObject(); // Hashcode field is always written as -1.
hashcode = tmpHashcode; s.writeInt(-1);
} }
/** /**
...@@ -766,10 +762,13 @@ public final class Locale implements Serializable, Cloneable ...@@ -766,10 +762,13 @@ public final class Locale implements Serializable, Cloneable
* @throws ClassNotFoundException if reading fails * @throws ClassNotFoundException if reading fails
* @serialData the hashCode is always invalid and must be recomputed * @serialData the hashCode is always invalid and must be recomputed
*/ */
private void readObject(ObjectInputStream input) private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException throws IOException, ClassNotFoundException
{ {
input.defaultReadObject(); language = (String) s.readObject();
country = (String) s.readObject();
variant = (String) s.readObject();
// Recompute hashcode.
hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode(); hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
} }
} // class Locale } // class Locale
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment