You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2005/06/30 20:40:38 UTC

cvs commit: xml-security/src/org/apache/xml/security/c14n/helper AttrCompare.java

raul        2005/06/30 11:40:38

  Modified:    src/org/apache/xml/security/c14n/implementations
                        CanonicalizerBase.java
               src/org/apache/xml/security/c14n/helper AttrCompare.java
  Log:
  Minor optimizations.
  
  Revision  Changes    Path
  1.19      +54 -46    xml-security/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java
  
  Index: CanonicalizerBase.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/implementations/CanonicalizerBase.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CanonicalizerBase.java	22 May 2005 19:19:18 -0000	1.18
  +++ CanonicalizerBase.java	30 Jun 2005 18:40:38 -0000	1.19
  @@ -211,7 +211,9 @@
       throws CanonicalizationException, IOException {
       	Node sibling=null;
       	Node parentNode=null;
  -    	OutputStream writer=this._writer;
  +    	final OutputStream writer=this._writer;
  +    	final Node excludeNode=this._excludeNode;
  +    	final boolean includeComments=this._includeComments;
       	do {
       		switch (currentNode.getNodeType()) {
       		
  @@ -233,7 +235,7 @@
       			break;
       			
       		case Node.COMMENT_NODE :
  -    			if (this._includeComments) {
  +    			if (includeComments) {
       				outputCommentToWriter((Comment) currentNode, writer);
       			}
       			break;
  @@ -248,7 +250,7 @@
       			break;
       			
       		case Node.ELEMENT_NODE :        
  -    			if (currentNode==this._excludeNode) {
  +    			if (currentNode==excludeNode) {
       				break;
       			}      
       			Element currentElement = (Element) currentNode;
  @@ -640,62 +642,68 @@
   
      final static void writeCharToUtf8(final char c,final OutputStream out) throws IOException{
      	char ch;
  -    if (/*(c >= 0x0001) &&*/ (c <= 0x007F)) {
  -   		out.write(c);
  -   		return;
  -   	} else if (c > 0x07FF) {
  -        ch=(char)(c>>>12);
  -        if (ch>0) {
  -        	out.write(0xE0 | ( ch & 0x0F));
  -        } else {
  -        	out.write(0xE0);
  -        }
  -        out.write(0x80 | ((c >>>  6) & 0x3F));
  -   		out.write(0x80 | ((c) & 0x3F));
  -   		return;
  -   		
  -   	} else {
  -        ch=(char)(c>>>6);
  +   	if (/*(c >= 0x0001) &&*/ (c <= 0x007F)) {
  +        out.write(c);
  +        return;
  +    }
  +    int bias;
  +    int write;
  +    if (c > 0x07FF) {
  +        ch=(char)(c>>>12);      
  +        write=0xE0;
           if (ch>0) {
  -        	out.write(0xC0 | (ch & 0x1F));
  -        } else {
  -        	out.write(0xC0);
  -        }
  -   		out.write(0x80 | ((c) & 0x3F));
  -   		return;   		
  -   	}
  +            write |= ( ch & 0x0F);
  +        } 
  +        out.write(write);
  +        write=0x80;
  +        bias=0x3F;        
  +    } else {
  +    	write=0xC0;
  +    	bias=0x1F;
  +    }
  +    ch=(char)(c>>>6);
  +    if (ch>0) {
  +         write|= (ch & bias);
  +    } 
  +    out.write(write);
  +    out.write(0x80 | ((c) & 0x3F));    
      	
      }
      
      final static void writeStringToUtf8(final String str,final OutputStream out) throws IOException{
      	final int length=str.length();
      	int i=0;
  -    char ch,c;
  +    char c;    
      	while (i<length) {
      		c=str.charAt(i++);        
           if (/*(c >= 0x0001) &&*/ (c <= 0x007F)) {
               out.write(c);
               continue;
  -        } else if (c > 0x07FF) {
  -            ch=(char)(c>>>12);
  +        }
  +        char ch;
  +        int bias;
  +        int write;
  +        if (c > 0x07FF) {
  +            ch=(char)(c>>>12);      
  +            write=0xE0;
               if (ch>0) {
  -                out.write(0xE0 | ( ch & 0x0F));
  -            } else {
  -                out.write(0xE0);
  -            }
  -            out.write(0x80 | ((c >>>  6) & 0x3F));
  -            out.write(0x80 | ((c) & 0x3F));
  -            continue;            
  +                write |= ( ch & 0x0F);
  +            } 
  +            out.write(write);
  +            write=0x80;
  +            bias=0x3F;        
           } else {
  -            ch=(char)(c>>>6);
  -            if (ch>0) {
  -                out.write(0xC0 | (ch & 0x1F));
  -            } else {
  -                out.write(0xC0);
  -            }
  -            out.write(0x80 | ((c) & 0x3F));
  -            continue;         
  -        }   		
  +        	write=0xC0;
  +        	bias=0x1F;
  +        }
  +        ch=(char)(c>>>6);
  +        if (ch>0) {
  +             write|= (ch & bias);
  +        } 
  +        out.write(write);
  +        out.write(0x80 | ((c) & 0x3F));
  +        continue;         
  +           		
      	}
       
      }
  
  
  
  1.12      +5 -4      xml-security/src/org/apache/xml/security/c14n/helper/AttrCompare.java
  
  Index: AttrCompare.java
  ===================================================================
  RCS file: /home/cvs/xml-security/src/org/apache/xml/security/c14n/helper/AttrCompare.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AttrCompare.java	5 Dec 2004 18:51:50 -0000	1.11
  +++ AttrCompare.java	30 Jun 2005 18:40:38 -0000	1.12
  @@ -127,11 +127,12 @@
         if (a != 0) {
         	return a;
         }
  +      /*
  +      String localName0 = ;
  +      String localName1 =;*/
         
  -      String localName0 = attr0.getLocalName();
  -      String localName1 = attr1.getLocalName();
  -      
  -      return localName0.compareTo(localName1);
  +      return (attr0.getLocalName())
  +      				.compareTo( attr1.getLocalName());
            
      }