8015379: PropertyMap.addProperty() is slow
authorhannesw
Tue, 11 Jun 2013 17:50:10 +0200
changeset 18325 35288b76c9ff
parent 18322 7d5c1fa9c82c
child 18326 512bdf9535a6
8015379: PropertyMap.addProperty() is slow Reviewed-by: attila, jlaskey
nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java
--- a/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java	Tue Jun 11 13:09:43 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/runtime/PropertyMap.java	Tue Jun 11 17:50:10 2013 +0200
@@ -95,7 +95,6 @@
      */
     private PropertyMap(final PropertyHashMap properties, final int fieldCount, final int fieldMaximum) {
         this.properties   = properties;
-        this.hashCode     = computeHashCode();
         this.fieldCount   = fieldCount;
         this.fieldMaximum = fieldMaximum;
 
@@ -125,7 +124,6 @@
         this.spillLength  = propertyMap.spillLength;
         this.fieldCount   = propertyMap.fieldCount;
         this.fieldMaximum = propertyMap.fieldMaximum;
-        this.hashCode     = computeHashCode();
 
         if (Context.DEBUG) {
             count++;
@@ -610,6 +608,9 @@
 
     @Override
     public int hashCode() {
+        if (hashCode == 0 && !properties.isEmpty()) {
+            hashCode = computeHashCode();
+        }
         return hashCode;
     }