harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r659012 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Date Thu, 22 May 2008 06:11:06 GMT
Author: varlax
Date: Wed May 21 23:11:06 2008
New Revision: 659012

URL: http://svn.apache.org/viewvc?rev=659012&view=rev
Log:
Applied HARMONY-5770 [classlib][luni][performance] ObjectOutputStream performs double lookups
in object storage

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java?rev=659012&r1=659011&r2=659012&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectOutputStream.java
Wed May 21 23:11:06 2008
@@ -368,7 +368,7 @@
      */
     private Integer dumpCycle(Object obj) throws IOException {
         // If the object has been saved already, save its handle only
-        Integer handle = registeredObjectHandleFor(obj);
+        Integer handle = objectsWritten.get(obj);
         if (handle != null) {
             writeCyclicReference(handle);
             return handle;
@@ -459,20 +459,6 @@
     }
 
     /**
-     * Return the <code>Integer</code> handle used to tag object
-     * <code>obj</code> as an instance that has been dumped already. Return
-     * <code>null</code> if object <code>obj</code> has not been
saved yet.
-     * 
-     * @param obj
-     *            the object
-     * @return null if object <code>obj</code> has not been saved yet. Integer
-     *         The handle that this object was assigned when it was saved.
-     */
-    private Integer registeredObjectHandleFor(Object obj) {
-        return objectsWritten.get(obj);
-    }
-
-    /**
      * Assume object <code>obj</code> has not been dumped yet, and assign a
      * handle to it
      * 
@@ -484,7 +470,7 @@
      */
     private Integer registerObjectWritten(Object obj) {
         Integer handle = Integer.valueOf(nextHandle());
-        registerObjectWritten(obj, handle);
+        objectsWritten.put(obj, handle);
         return handle;
     }
 
@@ -499,28 +485,13 @@
      */
     private void removeUnsharedReference(Object obj, Integer previousHandle) {
         if (previousHandle != null) {
-            registerObjectWritten(obj, previousHandle);
+            objectsWritten.put(obj, previousHandle);
         } else {
             objectsWritten.remove(obj);
         }
     }
 
     /**
-     * Assume object <code>obj</code> has not been dumped yet, and assign a
-     * handle to it, <code>handle</code>.
-     * 
-     * @param obj
-     *            Non-null object being dumped.
-     * @param handle
-     *            An Integer, the handle to this object
-     * 
-     * @see #nextHandle
-     */
-    private void registerObjectWritten(Object obj, Integer handle) {
-        objectsWritten.put(obj, handle);
-    }
-
-    /**
      * If <code>enableReplaceObject()</code> was activated, computes the
      * replacement object for the original object <code>object</code> and
      * returns the replacement. Otherwise returns <code>object</code>.
@@ -763,7 +734,10 @@
         }
         if (handle == null) {
             Class<?> classToWrite = classDesc.forClass();
-            Integer previousHandle = objectsWritten.get(classDesc);
+            Integer previousHandle = null;
+            if (unshared) {
+                previousHandle = objectsWritten.get(classDesc);
+            }
             // If we got here, it is a new (non-null) classDesc that will have
             // to be registered as well
             handle = registerObjectWritten(classDesc);
@@ -1207,7 +1181,10 @@
         output.writeByte(TC_ARRAY);
         writeClassDescForClass(arrayClass);
 
-        Integer previousHandle = objectsWritten.get(array);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(array);
+        }
         Integer handle = registerObjectWritten(array);
         if (unshared) {
             // remove reference to unshared object
@@ -1315,7 +1292,10 @@
                     unshared);
         }
 
-        Integer previousHandle = objectsWritten.get(object);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(object);
+        }
         Integer handle = registerObjectWritten(object);
         if (unshared) {
             // remove reference to unshared object
@@ -1449,7 +1429,10 @@
         // Either serializable or externalizable, now we can save info
         output.writeByte(TC_OBJECT);
         writeClassDescForClass(theClass);
-        Integer previousHandle = objectsWritten.get(object);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(object);
+        }
         Integer handle = registerObjectWritten(object);
 
         // This is how we know what to do in defaultWriteObject. And it is also
@@ -1521,7 +1504,10 @@
         }
         output.writeUTFBytes(object, count);
 
-        Integer previousHandle = objectsWritten.get(object);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(object);
+        }
         Integer handle = registerObjectWritten(object);
         if (unshared) {
             // remove reference to unshared object
@@ -1692,7 +1678,7 @@
                         // Make the original object also map to the same
                         // handle.
                         if (replacementHandle != null) {
-                            registerObjectWritten(object, replacementHandle);
+                            objectsWritten.put(object, replacementHandle);
                         }
                         return replacementHandle;
                     }
@@ -1713,7 +1699,7 @@
                             computeClassBasedReplacement, false);
                     // Make the original object also map to the same handle.
                     if (replacementHandle != null) {
-                        registerObjectWritten(object, replacementHandle);
+                        objectsWritten.put(object, replacementHandle);
                     }
                     return replacementHandle;
                 }
@@ -1760,7 +1746,10 @@
         ObjectStreamClass classDesc = ObjectStreamClass.lookup(theClass);
         // set flag for enum, the flag is (SC_SERIALIZABLE | SC_ENUM)
         classDesc.setFlags((byte) (SC_SERIALIZABLE | SC_ENUM));
-        Integer previousHandle = objectsWritten.get(classDesc);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(classDesc);
+        }
         Integer handle = null;
         if (!unshared) {
             handle = dumpCycle(classDesc);
@@ -1816,7 +1805,10 @@
         }
         ObjectStreamClass classDesc = writeEnumDesc(theClass, unshared);
 
-        Integer previousHandle = objectsWritten.get(object);
+        Integer previousHandle = null;
+        if (unshared) {
+            previousHandle = objectsWritten.get(object);
+        }
         Integer handle = registerObjectWritten(object);
 
         ObjectStreamField[] fields = classDesc.getSuperclass().fields();



Mime
View raw message