axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric.D.Fried...@wellsfargo.com
Subject RE: cvs commit: xml-axis/java/src/org/apache/axis AxisFault.java
Date Mon, 07 Jul 2003 20:08:09 GMT
Hi Tom,

Would that it were so, but Java's handling of concatenation is woefully
suboptimal where variables are involved.  I'm attaching a couple of files as
examples of this.  The first is a simple class which implements the same
string creation code in two ways: once using concatenation operations, and
again using StringBuffer.append() operations.  The second file is the output
of the bytecode disassembler on the compiled class.  You'll note that the
bytecodes for the concat() method contain repeated calls to new
StringBuffer() and then to toString() -- one for each instance of the
overloaded "+=" operator.  The result is a lot of extra GC thrash for
methods that use the concat() approach.

Eric



-----Original Message-----
From: Tom Jordahl [mailto:tomj@macromedia.com]
Sent: Monday, July 07, 2003 11:58 AM
To: 'axis-dev@ws.apache.org'
Subject: RE: cvs commit: xml-axis/java/src/org/apache/axis
AxisFault.java


Eric,

My understanding was that Java would "take care of that" when it encountered
string concatenation.  It would convert the x = a + b + c + .. + z; in to
code that would do the "smart" appending.

And the other way was easier to read. :-)

P.S. Welcome to Open Source!
--
Tom Jordahl
Macromedia Server Development

-----Original Message-----
From: ericf@apache.org [mailto:ericf@apache.org] 
Sent: Friday, June 27, 2003 1:43 AM
To: xml-axis-cvs@apache.org
Subject: cvs commit: xml-axis/java/src/org/apache/axis AxisFault.java

ericf       2003/06/26 22:43:03

  Modified:    java/src/org/apache/axis AxisFault.java
  Log:
  replaced extensive String concatenation code with equivalent
  StringBuffer.append code to reduce object creation
  
  Revision  Changes    Path
  1.80      +32 -38    xml-axis/java/src/org/apache/axis/AxisFault.java
  
  Index: AxisFault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisFault.java,v
  retrieving revision 1.79
  retrieving revision 1.80
  diff -u -r1.79 -r1.80
  --- AxisFault.java	29 May 2003 11:59:56 -0000	1.79
  +++ AxisFault.java	27 Jun 2003 05:43:03 -0000	1.80
  @@ -313,49 +313,43 @@
        */
       public String dumpToString()
       {
  -        String details = new String();
  -
  +        StringBuffer buf = new StringBuffer("AxisFault");
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultCode: ");
  +        buf.append(XMLUtils.xmlEncodeString(faultCode.toString()));
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultSubcode: ");
  +        if (faultSubCode != null) {
  +            for (int i = 0; i < faultSubCode.size(); i++) {
  +                buf.append(JavaUtils.LS);
  +                buf.append(faultSubCode.elementAt(i).toString());
  +            }
  +        }
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultString: ");
  +        buf.append(XMLUtils.xmlEncodeString(faultString));
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultActor: ");
  +        buf.append(XMLUtils.xmlEncodeString(faultActor));
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultNode: ");
  +        buf.append(XMLUtils.xmlEncodeString(faultNode));
  +        buf.append(JavaUtils.LS);
  +        buf.append(" faultDetail: ");
           if (faultDetails != null) {
               for (int i=0; i < faultDetails.size(); i++) {
                   Element e = (Element) faultDetails.get(i);
  -                String namespace= e.getNamespaceURI();
  -                if(namespace==null) {
  -                    namespace="";
  -                }
  -                String partname= e.getLocalName();
  -                if(partname==null) {
  -                    partname=e.getNodeName();
  -                }
  -                details += JavaUtils.LS
  -                          + "\t{" + namespace + "}"
  -                          + partname + ": "
  -                          + XMLUtils.getInnerXMLString(e);
  -            }
  -        }
  -
  -        String subCodes = new String();
  -        if (faultSubCode != null) {
  -            for (int i = 0; i < faultSubCode.size(); i++) {
  -                subCodes += JavaUtils.LS
  -                            + (QName)faultSubCode.elementAt(i);
  +                buf.append(JavaUtils.LS);
  +                buf.append("\t{");
  +                buf.append(null == e.getNamespaceURI() ? "" :
e.getNamespaceURI());
  +                buf.append("}");
  +                buf.append(null == e.getLocalName() ? "" :
e.getLocalName());
  +                buf.append(":");
  +                buf.append(XMLUtils.getInnerXMLString(e));
               }
           }
  -        //encode everything except details and subcodes, which are
already
  -        //dealt with one way or another.
  -        String code= XMLUtils.xmlEncodeString(faultCode.toString());
  -        String errorString= XMLUtils.xmlEncodeString(faultString);
  -        String actor= XMLUtils.xmlEncodeString(faultActor);
  -        String node= XMLUtils.xmlEncodeString(faultNode);
  -
  -
  -        return "AxisFault" + JavaUtils.LS
  -            + " faultCode: " + code + JavaUtils.LS
  -            + " faultSubcode: " + subCodes + JavaUtils.LS
  -            + " faultString: " + errorString + JavaUtils.LS
  -            + " faultActor: " + actor + JavaUtils.LS
  -            + " faultNode: " + node + JavaUtils.LS
  -            + " faultDetail: " + details + JavaUtils.LS
  -            ;
  +        buf.append(JavaUtils.LS);
  +        return buf.toString();
       }
   
       /**
  
  
  


Mime
View raw message