diff options
| author | Roman Kennke <roman@kennke.org> | 2007-09-21 08:33:42 +0000 |
|---|---|---|
| committer | Roman Kennke <roman@kennke.org> | 2007-09-21 08:33:42 +0000 |
| commit | f7b95ca2b1837ec6accb197d41d67fc3dfde3f95 (patch) | |
| tree | f120dd2cc2bf6047b503b0be399670764972f587 /java | |
| parent | 3eaf3f44a0e41fea77a3e39535b17d455d056a49 (diff) | |
| download | classpath-f7b95ca2b1837ec6accb197d41d67fc3dfde3f95.tar.gz | |
2007-09-21 Roman Kennke <roman.kennke@aicas.com>
* java/awt/Font.java
(hashCode): New field. Stores a cached hash code.
(hashCode()): Re-implemented. Don't create new string here, instead
make hashcode of name, style, size and transform. Cache hashcode.
Diffstat (limited to 'java')
| -rw-r--r-- | java/awt/Font.java | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/java/awt/Font.java b/java/awt/Font.java index d6892a626..4e6e6bd34 100644 --- a/java/awt/Font.java +++ b/java/awt/Font.java @@ -229,6 +229,11 @@ public class Font implements Serializable // The ClasspathToolkit-provided peer which implements this font private transient ClasspathFontPeer peer; + /** + * The cached hashcode. A value of 0 (default initialized) means that the + * hashcode is not computed yet. + */ + private transient int hashCode; /** * Creates a <code>Font</code> object from the specified string, which @@ -1318,7 +1323,21 @@ public class Font implements Serializable */ public int hashCode() { - return this.toString().hashCode(); + // We cache the hashcode. This makes sense, because the font wouldn't + // change the relevant properties. + if (hashCode == 0) + { + hashCode = getName().hashCode() ^ getTransform().hashCode() ^ getSize() + ^ getStyle(); + // In the rare case when the above yields 0, we set this to some other + // value to avoid recomputing over and over again. This is still + // conform to the specification of hashCode(). + if (hashCode == 0) + { + hashCode = -1; + } + } + return hashCode; } |
