You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Nicholas Barratt <nb...@akiva.com> on 2002/09/27 22:49:26 UTC

Trivial fix for xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java

It seems that ",ch="+ch would instantiate a new String object, while the
replacement below would not.  I imagine that many compilers would
optimize this out, but you never know.  My compiler gives a warning for
the current code.

  Index: XMLEntityManager.java
  ===================================================================
  RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityMana
ger.java,v
  retrieving revision 1.47
  diff -u -r1.47 XMLEntityManager.java
  --- XMLEntityManager.java	24 Sep 2002 09:39:44 -0000	1.47
  +++ XMLEntityManager.java	27 Sep 2002 20:44:19 -0000
  @@ -2047,7 +2047,8 @@
   
               StringBuffer str = new StringBuffer();
               str.append("name=\""+name+'"');
  -            str.append(",ch="+ch);
  +            str.append(",ch=");
  +            str.append(ch);
               str.append(",position="+position);
               str.append(",count="+count);
               return str.toString();

--

Nick Barratt (nbarratt@akiva.com)
Software Architect
Akiva Corp (http://www.akiva.com)
Akiva - Idea Technologies 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Trivial fix for xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java

Posted by Andy Clark <an...@apache.org>.
Nicholas Barratt wrote:
>                str.append("name=\""+name+'"');
>   -            str.append(",ch="+ch);
>   +            str.append(",ch=");
>   +            str.append(ch);
>                str.append(",position="+position);
>                str.append(",count="+count);

This isn't really needed that much since this method
is only there for debugging purposes and would not be
called in general operation. Besides, if you want to
make this kind of change to avoid having the compiler
generate additional StringBuffer objects, you should
change *all* of the occurrences of string concats.

But my opinion is that this inefficiency is fine for
debugging and error messages since these occur rarely.
However, if this kind of thing were in the inner loop
of the scanner, then we would definitely want to
reconsider the approach and try to be as efficient as
possible.

-- 
Andy Clark * andyc@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org