diff --git a/src/helma/objectmodel/db/DbKey.java b/src/helma/objectmodel/db/DbKey.java index d5fc2a77..ff8b5041 100644 --- a/src/helma/objectmodel/db/DbKey.java +++ b/src/helma/objectmodel/db/DbKey.java @@ -21,6 +21,9 @@ public final class DbKey implements Key, Serializable { // the id that defines this key's object within the above storage space private final String id; + // lazily initialized hashcode + private transient int hashcode = 0; + /** * make a key for a persistent Object, describing its datasource and id. */ @@ -44,7 +47,12 @@ public final class DbKey implements Key, Serializable { } public int hashCode () { - return storageName == null ? id.hashCode () : storageName.hashCode() + id.hashCode (); + if (hashcode == 0) { + hashcode = storageName == null ? + 17 + 37*id.hashCode () : + 17 + 37*storageName.hashCode() + +37*id.hashCode (); + } + return hashcode; } public Key getParentKey () { diff --git a/src/helma/objectmodel/db/SyntheticKey.java b/src/helma/objectmodel/db/SyntheticKey.java index 86934505..7f1911ac 100644 --- a/src/helma/objectmodel/db/SyntheticKey.java +++ b/src/helma/objectmodel/db/SyntheticKey.java @@ -16,6 +16,9 @@ public final class SyntheticKey implements Key, Serializable { private final Key parentKey; private final String name; + // lazily initialized hashcode + private transient int hashcode = 0; + /** * make a key for a persistent Object, describing its datasource and id. @@ -39,7 +42,9 @@ public final class SyntheticKey implements Key, Serializable { } public int hashCode () { - return name.hashCode () + parentKey.hashCode (); + if (hashcode == 0) + hashcode = 17 + 37*name.hashCode () + 37*parentKey.hashCode (); + return hashcode; }