You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2002/10/21 13:09:41 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/dtd DTDGrammar.java XMLDTDValidator.java

neeraj      2002/10/21 04:09:40

  Modified:    java/src/org/apache/xerces/impl/dtd DTDGrammar.java
                        XMLDTDValidator.java
  Log:
  Peformance patch for XMLDTDValidator. Optimizing addDefaultAttributeValidate (hotspot) Passing elementname object to addDTDDefaultAttrsAndValidate, we already have this information available and can directly pass it. Greatly reduces the invocations of DTDGrammar.getElementDecl() (another hotspot).
  
  Made new function 'getContentSpecType(int:elementIndex):short' in DTDGrammar
  to get contentSpecType info.We can straight away fetch this value from 2D arrays using elementIndex and  can avoid
  filling of values in temporary elementDeclaration object and then getting the actual value.
  
  Revision  Changes    Path
  1.20      +22 -1     xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java
  
  Index: DTDGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DTDGrammar.java	24 Jul 2002 15:04:59 -0000	1.19
  +++ DTDGrammar.java	21 Oct 2002 11:09:39 -0000	1.20
  @@ -1238,6 +1238,27 @@
           return getElementDeclIndex(elementDeclQName.rawname);
       } // getElementDeclIndex(QName):int
      
  +		/** make separate function for getting contentSpecType of element.
  +      * we can avoid setting of the element values.
  +		*/
  +
  +		public short getContentSpecType(int elementIndex){
  +        if (elementIndex < 0 || elementIndex >= fElementDeclCount) {
  +            return -1 ;
  +        }
  +
  +        int chunk = elementIndex >> CHUNK_SHIFT;
  +        int index = elementIndex &  CHUNK_MASK;
  +			
  +        if(fElementDeclType[chunk][index] == -1){
  +            return -1 ;
  +			    }
  +        else{
  +				       return (short) (fElementDeclType[chunk][index] & LIST_MASK);
  +			    }
  +
  +		}//getContentSpecType
  +
       /**
        * getElementDecl
        * 
  
  
  
  1.39      +13 -15    xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
  
  Index: XMLDTDValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- XMLDTDValidator.java	25 Sep 2002 15:53:47 -0000	1.38
  +++ XMLDTDValidator.java	21 Oct 2002 11:09:40 -0000	1.39
  @@ -1124,8 +1124,10 @@
                                && (fDTDValidation || fSeenDoctypeDecl);
       }
       
  +			//REVISIT:we can convert into functions.. adding default attribute values.. and one validating.
  +
       /** Add default attributes and validate. */
  -    protected void addDTDDefaultAttrsAndValidate(int elementIndex, 
  +    protected void addDTDDefaultAttrsAndValidate(QName elementName, int elementIndex, 
                                                  XMLAttributes attributes) 
       throws XNIException {
   
  @@ -1134,10 +1136,6 @@
               return;
           }
   
  -        // get element info
  -        fDTDGrammar.getElementDecl(elementIndex,fTempElementDecl);
  -        QName element = fTempElementDecl.name;
  -
           //
           // Check after all specified attrs are scanned
           // (1) report error for REQUIRED attrs that are missing (V_TAGc)
  @@ -1190,7 +1188,7 @@
               if (!specified) {
                   if (required) {
                       if (fValidation) {
  -                        Object[] args = {element.localpart, attRawName};
  +                        Object[] args = {elementName.localpart, attRawName};
                           fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                      "MSG_REQUIRED_ATTRIBUTE_NOT_SPECIFIED", args,
                                                      XMLErrorReporter.SEVERITY_ERROR);
  @@ -1200,7 +1198,7 @@
                       if (fPerformValidation && fGrammarBucket.getStandalone()) {
                           if (fDTDGrammar.getAttributeDeclIsExternal(attlistIndex)) {
   
  -                            Object[] args = { element.localpart, attRawName};
  +                            Object[] args = { elementName.localpart, attRawName};
                               fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                          "MSG_DEFAULTED_ATTRIBUTE_NOT_SPECIFIED", args,
                                                          XMLErrorReporter.SEVERITY_ERROR);
  @@ -1271,7 +1269,7 @@
                   if (fPerformValidation) {
                       // REVISIT - cache the elem/attr tuple so that we only
                       // give this error once for each unique occurrence
  -                    Object[] args = { element.rawname, attrRawName};
  +                    Object[] args = { elementName.rawname, attrRawName};
   
                       fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                  "MSG_ATTRIBUTE_NOT_DECLARED",
  @@ -1313,7 +1311,7 @@
                   String defaultValue = fTempAttDecl.simpleType.defaultValue;
   
                   if (!attrValue.equals(defaultValue)) {
  -                    Object[] args = {element.localpart,
  +                    Object[] args = {elementName.localpart,
                           attrRawName,
                           attrValue,
                           defaultValue};
  @@ -1330,7 +1328,7 @@
                   fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NMTOKEN ||
                   fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NOTATION
                  ) {
  -                validateDTDattribute(element, attrValue, fTempAttDecl);
  +                validateDTDattribute(elementName, attrValue, fTempAttDecl);
               }
           } // for all attributes
   
  @@ -1922,8 +1920,8 @@
           else {
               //  resolve the element
               fCurrentElementIndex = fDTDGrammar.getElementDeclIndex(element);
  -
  -            fCurrentContentSpecType = getContentSpecType(fCurrentElementIndex);
  +									//changed here.. new function for getContentSpecType
  +            fCurrentContentSpecType = fDTDGrammar.getContentSpecType(fCurrentElementIndex);
               if (fCurrentContentSpecType == -1 && fPerformValidation) {
                   fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 
                                              "MSG_ELEMENT_NOT_DECLARED",
  @@ -1935,8 +1933,8 @@
                   //  1. normalize the attributes
                   //  2. validate the attrivute list.
                   // TO DO: 
  -                // 
  -                addDTDDefaultAttrsAndValidate(fCurrentElementIndex, attributes);
  +												//changed here.. also pass element name,
  +                addDTDDefaultAttrsAndValidate(element, fCurrentElementIndex, attributes);
               }
           }
   
  
  
  

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