mrglavas    2004/04/07 08:42:05

  Modified:    java/src/org/apache/xerces/parsers AbstractSAXParser.java
  Log:
  Fixing a bug.

  

  Back out preformance improvement made in Xerces 2.6.2 to

  prevent the iterative search over an attribute list for

  namespace attributes when no namespaces have been

  declared in the current context. Testing if there are no

  declared prefixes doesn't work in the case where an instance

  document contains the declaration 

  xmlns:xml='http://www.w3.org/XML/1998/namespace' on an

  element with no other namespace declarations. Since we don't

  report this mapping to the namespace context such declarations

  would be missed and then appear in the SAX event stream in

  error.

  

  Since the strings of a QName are always interned, use reference

  comparison instead of equals to buy a little performance back.
  
  Revision  Changes    Path
  1.54      +26 -26    
xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java
  
  Index: AbstractSAXParser.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractSAXParser.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- AbstractSAXParser.java    25 Mar 2004 04:03:23 -0000      1.53
  +++ AbstractSAXParser.java    7 Apr 2004 15:42:05 -0000       1.54
  @@ -25,6 +25,7 @@
   import org.apache.xerces.util.ErrorHandlerWrapper;
   import org.apache.xerces.util.SAXMessageFormatter;
   import org.apache.xerces.util.SymbolHash;
  +import org.apache.xerces.util.XMLSymbols;
   import org.apache.xerces.xni.Augmentations;
   import org.apache.xerces.xni.NamespaceContext;
   import org.apache.xerces.xni.QName;
  @@ -438,30 +439,30 @@
                   
                   if (fNamespaces) {
                       // send prefix mapping events
  -                    int count = startNamespaceMapping();
  +                    startNamespaceMapping();
   
  -                    // If there were no new namespaces declared
  -                    // then we can skip searching the attribute list
  -                    // for namespace declarations.
  -                    if (count > 0) {
  -                        int len = attributes.getLength();
  -                        for (int i = len - 1; i >= 0; i--) {
  -                            attributes.getName(i, fQName);
  -
  -                            if ((fQName.prefix != null && 
fQName.prefix.equals("xmlns")) || 
  -                                fQName.rawname.equals("xmlns")) {
  -                                if (!fNamespacePrefixes) {
  -                                    // remove namespace declaration attributes
  -                                    attributes.removeAttributeAt(i);
  -                                }
  -                                else {
  -                                    // localpart should be empty string as per SAX 
documentation:
  -                                    // 
http://www.saxproject.org/?selected=namespaces
  -                                    fQName.prefix = "";
  -                                    fQName.uri = "";
  -                                    fQName.localpart = "";
  -                                    attributes.setName(i, fQName);
  -                                }
  +                    // REVISIT: It should not be necessary to iterate over the 
attribute
  +                    // list when the set of [namespace attributes] is empty for this
  +                    // element. This should be computable from the 
NamespaceContext, but
  +                    // since we currently don't report the mappings for the xml 
prefix
  +                    // we cannot use the declared prefix count for the current 
context
  +                    // to skip this section. -- mrglavas
  +                    int len = attributes.getLength();
  +                    for (int i = len - 1; i >= 0; --i) {
  +                        attributes.getName(i, fQName);    
  +                        if ((fQName.prefix == XMLSymbols.PREFIX_XMLNS) || 
  +                            (fQName.rawname == XMLSymbols.PREFIX_XMLNS)) {
  +                            if (!fNamespacePrefixes) {
  +                                // remove namespace declaration attributes
  +                                attributes.removeAttributeAt(i);
  +                            }
  +                            else {
  +                                // localpart should be empty string as per SAX 
documentation:
  +                                // http://www.saxproject.org/?selected=namespaces
  +                                fQName.prefix = "";
  +                                fQName.uri = "";
  +                                fQName.localpart = "";
  +                                attributes.setName(i, fQName);
                               }
                           }
                       }
  @@ -1926,7 +1927,7 @@
       /**
        * Send startPrefixMapping events
        */
  -    protected final int startNamespaceMapping() throws SAXException{
  +    protected final void startNamespaceMapping() throws SAXException{
           int count = fNamespaceContext.getDeclaredPrefixCount();
           if (count > 0) {
               String prefix = null;
  @@ -1938,7 +1939,6 @@
                       (uri == null) ? "" : uri);
               }
           }
  -        return count;
       }
       
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to