/[classpath]/classpath/java/util/Locale.java
ViewVC logotype

Diff of /classpath/java/util/Locale.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by mkoch, Fri Mar 19 08:05:59 2004 UTC revision 1.19 by bryce, Mon Jul 5 23:30:33 2004 UTC
# Line 186  public final class Locale implements Ser Line 186  public final class Locale implements Ser
186     *     *
187     * @serial should be -1 in serial streams     * @serial should be -1 in serial streams
188     */     */
189    private int hashcode;    private transient int hashcode;
190    
191    /**    /**
192     * The default locale. Except for during bootstrapping, this should never be     * The default locale. Except for during bootstrapping, this should never be
# Line 709  public final class Locale implements Ser Line 709  public final class Locale implements Ser
709     *     *
710     * @return the hashcode     * @return the hashcode
711     */     */
712    public synchronized int hashCode()    public int hashCode()
713    {    {
     // This method is synchronized because writeObject() might reset  
     // the hashcode.  
714      return hashcode;      return hashcode;
715    }    }
716    
# Line 731  public final class Locale implements Ser Line 729  public final class Locale implements Ser
729        return false;        return false;
730      Locale l = (Locale) obj;      Locale l = (Locale) obj;
731    
     // ??? 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.  
732      return (language == l.language      return (language == l.language
733              && country == l.country              && country == l.country
734              && variant == l.variant);              && variant == l.variant);
# Line 745  public final class Locale implements Ser Line 739  public final class Locale implements Ser
739     *     *
740     * @param output the stream to write to     * @param output the stream to write to
741     * @throws IOException if the write fails     * @throws IOException if the write fails
742     * @serialData the hashcode should always be written as -1, and recomputed     * @serialData The first three fields are Strings representing language,
743     *      when reading it back     *             country, and variant. The fourth field is a placeholder for
744       *             the cached hashcode, but this is always written as -1, and
745       *             recomputed when reading it back.
746     */     */
747    private synchronized void writeObject(ObjectOutputStream output)    private void writeObject(ObjectOutputStream s)
748      throws IOException      throws IOException
749    {    {
750      // Synchronized so that hashCode() doesn't get wrong value.      s.writeObject(language);
751      int tmpHashcode = hashcode;      s.writeObject(country);
752      hashcode = -1;      s.writeObject(variant);
753      output.defaultWriteObject();      // Hashcode field is always written as -1.
754      hashcode = tmpHashcode;      s.writeInt(-1);
755    }    }
756    
757    /**    /**
# Line 766  public final class Locale implements Ser Line 762  public final class Locale implements Ser
762     * @throws ClassNotFoundException if reading fails     * @throws ClassNotFoundException if reading fails
763     * @serialData the hashCode is always invalid and must be recomputed     * @serialData the hashCode is always invalid and must be recomputed
764     */     */
765    private void readObject(ObjectInputStream input)    private void readObject(ObjectInputStream s)
766      throws IOException, ClassNotFoundException      throws IOException, ClassNotFoundException
767    {    {
768      input.defaultReadObject();      language = ((String) s.readObject()).intern();
769        country = ((String) s.readObject()).intern();
770        variant = ((String) s.readObject()).intern();
771        // Recompute hashcode.
772      hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();      hashcode = language.hashCode() ^ country.hashCode() ^ variant.hashCode();
773    }    }
774  } // class Locale  } // class Locale

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26