Hello,

XMLJavaMappingRegistry.getKey function uses Class.toString(), which is not
efficient and causes StringBuffer allocation, then expand, since original
size is not enough. In the same time for using as key it is enough to use
class name.

The Class.toString function is following (from SUN's SDK 1.3.1)

    public String toString() {
        return (isInterface() ? "interface " : (isPrimitive() ? "" : "class
"))
            + getName();
    }

I just created separated getKey functions for Class and QName, and added
special case for null values. It is saved me about 10% of all char[]
allocated (only memory usage was tracked)


Best regards,
Pavel

Index: XMLJavaMappingRegistry.java
===================================================================
RCS file: 
/home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/XMLJavaMappingRegistry.java,v
retrieving revision 1.10
diff -u -r1.10 XMLJavaMappingRegistry.java
--- XMLJavaMappingRegistry.java 23 Oct 2002 19:35:19 -0000      1.10
+++ XMLJavaMappingRegistry.java 29 Oct 2002 16:53:58 -0000
@@ -92,7 +92,7 @@
   private Hashtable java2XMLReg = new Hashtable();
   /** Encoding to use if none specified */
   private String defaultEncodingStyle = null;
-  
+
   /**
    * Sets the default encoding style.  If the query*() calls
    * are invoked with a null encodingStyleURI parameter, we'll
@@ -117,7 +117,7 @@
    * To register a default serializer and/or deserializer, set the
    * corresponding type to null.
    *
-   * @param encodingStyleURI The encoding style for the map.  The 
+   * @param encodingStyleURI The encoding style for the map.  The
    *        encoding style qualifies the types.
    * @param elementType The XML type.
    * @param javaType The Java type.
@@ -153,7 +153,7 @@
   }
 
   /**
-   * This version returns null if the serializer is not found. It is 
+   * This version returns null if the serializer is not found. It is
    * intended for internal usage (its used for chaining registries,
    * for example).
    *
@@ -177,14 +177,13 @@
     }
     else
     {
-      java2XMLKey = getKey(null, encodingStyleURI);
-      return (Serializer)sReg.get(java2XMLKey);
+      return (Serializer)sReg.get(encodingStyleURI);
     }
   }
 
   /**
    * This version calls the protected method to do the work and if it's
-   * not found throws an exception. 
+   * not found throws an exception.
    *
    * @param javaType The Java type.
    * @param encodingStyleURI The encoding style.
@@ -210,7 +209,7 @@
   }
 
   /**
-   * This version returns null if the deserializer is not found. It is 
+   * This version returns null if the deserializer is not found. It is
    * intended for internal usage (its used for chaining registries,
    * for example).
    *
@@ -235,14 +234,13 @@
     }
     else
     {
-      xml2JavaKey = getKey(null, encodingStyleURI);
-      return (Deserializer)dsReg.get(xml2JavaKey);
+      return (Deserializer)dsReg.get(encodingStyleURI);
     }
   }
 
   /**
    * This version calls the protected method to do the work and if its
-   * not found throws an exception. 
+   * not found throws an exception.
    *
    * @param elementType The XML type.
    * @param encodingStyleURI The encoding style.
@@ -268,7 +266,7 @@
   }
 
   /**
-   * This version returns null if the element type is not found. It is 
+   * This version returns null if the element type is not found. It is
    * intended for internal usage (its used for chaining registries,
    * for example).
    *
@@ -289,7 +287,7 @@
 
   /**
    * This version calls the protected method to do the work and if its
-   * not found throws an exception. 
+   * not found throws an exception.
    *
    * @param javaType The Java type.
    * @param encodingStyleURI The encoding style.
@@ -314,7 +312,7 @@
   }
 
   /**
-   * This version returns null if the Java type is not found. It is 
+   * This version returns null if the Java type is not found. It is
    * intended for internal usage (its used for chaining registries,
    * for example).
    *
@@ -335,7 +333,7 @@
 
   /**
    * This version calls the protected method to do the work and if its
-   * not found throws an exception. 
+   * not found throws an exception.
    *
    * @param elementType The XML type.
    * @param encodingStyleURI The encoding style.
@@ -404,9 +402,26 @@
    * @param encodingStyleURI The encoding style.
    * @return The key.
    */
-  private static String getKey(Object type, String encodingStyleURI)
+  private static String getKey(QName type, String encodingStyleURI)
   {
+    if (type == null)
+          return encodingStyleURI;
     String strObj = String.valueOf(type);
+    return new StringBuffer(strObj.length() + 3 + 
+encodingStyleURI.length()).append(strObj).append(" + 
+").append(encodingStyleURI).toString();
+  }
+
+  /**
+   * Creates a key for the registry Hashtables.
+   *
+   * @param type The Java type (as a Class) or the XML type (as a QName).
+   * @param encodingStyleURI The encoding style.
+   * @return The key.
+   */
+  private static String getKey(Class type, String encodingStyleURI)
+  {
+    if (type == null)
+        return encodingStyleURI;
+    String strObj = type.getName();
     return new StringBuffer(strObj.length() + 3 + 
encodingStyleURI.length()).append(strObj).append(" + 
").append(encodingStyleURI).toString();
   }
 

--
To unsubscribe, e-mail:   <mailto:soap-dev-unsubscribe@;xml.apache.org>
For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>

Reply via email to