mrglavas    2005/05/24 19:28:39

  Modified:    java/src/org/apache/xerces/impl/xs/identity Field.java
  Log:
  Performance:
  
  Eliminate switch block in convertToPrimitiveKind(short). Bias checks towards 
primitive types.
  In convertToPrimitiveKind(ShortList) avoid creating a new list if all the 
items in the original
  list are primitive types already.
  
  Revision  Changes    Path
  1.20      +31 -35    
xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/impl/xs/identity/Field.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Field.java        9 May 2005 21:03:33 -0000       1.19
  +++ Field.java        25 May 2005 02:28:39 -0000      1.20
  @@ -183,46 +183,42 @@
           } // matched(String)
   
           private short convertToPrimitiveKind(short valueType) {
  -            switch(valueType) {
  -            
  -            case XSConstants.ID_DT:
  -            case XSConstants.IDREF_DT:
  -            case XSConstants.ENTITY_DT:
  -            case XSConstants.NCNAME_DT:
  -            case XSConstants.NAME_DT:
  -            case XSConstants.LANGUAGE_DT:
  -            case XSConstants.NMTOKEN_DT:
  -            case XSConstants.TOKEN_DT:
  -            case XSConstants.NORMALIZEDSTRING_DT:
  -                return XSConstants.STRING_DT;
  -                
  -            case XSConstants.UNSIGNEDBYTE_DT:
  -            case XSConstants.UNSIGNEDINT_DT:
  -            case XSConstants.UNSIGNEDLONG_DT:
  -            case XSConstants.UNSIGNEDSHORT_DT:
  -            case XSConstants.BYTE_DT:
  -            case XSConstants.SHORT_DT:
  -            case XSConstants.INT_DT:
  -            case XSConstants.POSITIVEINTEGER_DT:
  -            case XSConstants.NEGATIVEINTEGER_DT:
  -            case XSConstants.NONNEGATIVEINTEGER_DT:
  -            case XSConstants.NONPOSITIVEINTEGER_DT:
  -            case XSConstants.LONG_DT:
  -            case XSConstants.INTEGER_DT:
  -                return XSConstants.DECIMAL_DT;    
  -                
  -            default:
  +            /** Primitive datatypes. */
  +            if (valueType <= XSConstants.NOTATION_DT) {
                   return valueType;
               }
  +            /** Types derived from string. */
  +            if (valueType <= XSConstants.ENTITY_DT) {
  +                return XSConstants.STRING_DT;
  +            }
  +            /** Types derived from decimal. */
  +            if (valueType <= XSConstants.POSITIVEINTEGER_DT) {
  +                return XSConstants.DECIMAL_DT;
  +            }
  +            /** Other types. */
  +            return valueType;
           }
   
           private ShortList convertToPrimitiveKind(ShortList itemValueType) {
  -            if(itemValueType != null) {
  -                short[] arr = new short[itemValueType.getLength()];
  -                for(int i = 0;i < arr.length; i++) {
  -                    arr[i] = convertToPrimitiveKind(itemValueType.item(i));
  +            if (itemValueType != null) {
  +                int i;
  +                final int length = itemValueType.getLength();
  +                for (i = 0; i < length; ++i) {
  +                    short type = itemValueType.item(i);
  +                    if (type != convertToPrimitiveKind(type)) {
  +                        break;
  +                    }
  +                }
  +                if (i != length) {
  +                    final short [] arr = new short[length];
  +                    for (int j = 0; j < i; ++j) {
  +                        arr[j] = itemValueType.item(j);
  +                    }
  +                    for(; i < length; ++i) {
  +                        arr[i] = 
convertToPrimitiveKind(itemValueType.item(i));
  +                    }
  +                    return new ShortListImpl(arr, arr.length);
                   }
  -                return new ShortListImpl(arr, arr.length);
               }
               return itemValueType;
           }
  
  
  

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

Reply via email to