morten      01/07/23 08:24:00

  Modified:    java/src/org/apache/xalan/xsltc/compiler Import.java
                        Sort.java
               java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
                        NodeSortRecordFactory.java
  Log:
  For some reason I decided to optimise the <xsl:sort> functionaility. The
  sort records we used has some global values stored behind methods, but are
  now static fields. Somewhat faster.
  PR:           n/a
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.7       +3 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java
  
  Index: Import.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Import.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Import.java       2001/07/20 15:24:32     1.6
  +++ Import.java       2001/07/23 15:24:00     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Import.java,v 1.6 2001/07/20 15:24:32 morten Exp $
  + * @(#)$Id: Import.java,v 1.7 2001/07/23 15:24:00 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -104,6 +104,8 @@
                input = loader.loadSource(base, systemId, xsltc);
            }
            else {
  +             //System.err.println("current context is 
"+context.getSystemId());
  +             //System.err.println("new file  is "+systemId);
                input = new InputSource(systemId);
            }
   
  
  
  
  1.4       +7 -98     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java
  
  Index: Sort.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Sort.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Sort.java 2001/06/06 10:45:27     1.3
  +++ Sort.java 2001/07/23 15:24:00     1.4
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Sort.java,v 1.3 2001/06/06 10:45:27 morten Exp $
  + * @(#)$Id: Sort.java,v 1.4 2001/07/23 15:24:00 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -228,12 +228,8 @@
        final InstructionList il = methodGen.getInstructionList();
        
        // NodeSortRecordFactory.NodeSortRecordFactory(dom,class,levels,trlet);
  -     final String initParams = "("
  -         + DOM_INTF_SIG
  -         + STRING_SIG
  -         + "I"
  -         + TRANSLET_INTF_SIG
  -         + ")V";
  +     final String initParams =
  +         "("+DOM_INTF_SIG+STRING_SIG+ TRANSLET_INTF_SIG+")V";
        final int init = cpg.addMethodref(NODE_SORT_FACTORY,
                                          "<init>", initParams);
   
  @@ -247,7 +243,6 @@
        il.append(DUP);
        il.append(methodGen.loadDOM());
        il.append(new PUSH(cpg, className));
  -     il.append(new PUSH(cpg, sortObjects.size()));
        il.append(classGen.loadTranslet());
        il.append(new INVOKESPECIAL(init));
       }
  @@ -276,16 +271,9 @@
                                         cpg, className);
        Method extract = compileExtract(sortObjects, sortRecord,
                                        cpg, className);
  -     Method sortType = compileSortType(sortObjects, sortRecord,
  -                                       cpg, className);
  -     Method sortOrder = compileSortOrder(sortObjects, sortRecord,
  -                                         cpg, className);
  -
        sortRecord.addMethod(clinit);
        sortRecord.addEmptyConstructor(ACC_PUBLIC);
        sortRecord.addMethod(extract);
  -     sortRecord.addMethod(sortType);
  -     sortRecord.addMethod(sortOrder);
   
        // Overload NodeSortRecord.getCollator() only if needed
        for (int i = 0; i < sortObjects.size(); i++) {
  @@ -333,25 +321,12 @@
        final int setStrength = cpg.addMethodref(COLLATOR_CLASS,
                                                 "setStrength", "(I)V");
   
  -     // GTM: BCEL Changes:
  -     // GTM: Chged Field.ACC_PRIVATE --> Constants.ACC_PRIVATE
  -     //      Chged Field.ACC_STATIC  --> Constants.ACC_STATIC        
  -     sortRecord.addField(new Field(
  -                             Constants.ACC_PRIVATE | Constants.ACC_STATIC,
  -                             cpg.addUtf8("_compareType"),
  -                             cpg.addUtf8("[I"),
  -                             null, cpg.getConstantPool()));
  -     // GTM: BCEL Changes:
  -     // GTM: Chged Field.ACC_PRIVATE --> Constants.ACC_PRIVATE
  -     //      Chged Field.ACC_STATIC  --> Constants.ACC_STATIC        
  -     sortRecord.addField(new Field(
  -                             Constants.ACC_PRIVATE | Constants.ACC_STATIC,
  -                             cpg.addUtf8("_sortOrder"),
  -                             cpg.addUtf8("[I"),
  -                             null, cpg.getConstantPool()));
  -
        final int levels = sortObjects.size();
   
  +     final int levelsField = cpg.addFieldref(className, "_levels", "I");
  +     il.append(new PUSH(cpg, levels));
  +     il.append(new PUTSTATIC(levelsField));
  +
        // Compile code that initializes the static _compareType array
        final int ctype = cpg.addFieldref(className, "_compareType", "[I");
        il.append(new PUSH(cpg,levels));
  @@ -500,72 +475,6 @@
        extractMethod.removeNOPs();
   
        return extractMethod.getMethod();
  -    }
  -
  -
  -    /**
  -     * Compiles a method that overloads NodeSortRecord.compareType()
  -     */
  -    private static Method compileSortType(Vector sortObjects,
  -                                       NodeSortRecordGenerator sortRecord,
  -                                       ConstantPoolGen cpg,
  -                                       String className) {
  -     final InstructionList il = new InstructionList();
  -     
  -     // int NodeSortRecord.compareType(level);
  -     final MethodGenerator sortType =
  -         new MethodGenerator(ACC_PUBLIC | ACC_FINAL,
  -                             de.fub.bytecode.generic.Type.INT, 
  -                             new de.fub.bytecode.generic.Type[] {
  -                                 de.fub.bytecode.generic.Type.INT
  -                             },
  -                             new String[] { "level" },
  -                             "compareType", className, il, cpg);
  -     final int idx = cpg.addFieldref(className, "_compareType", "[I");
  -     il.append(new GETSTATIC(idx));
  -     il.append(new ILOAD(sortType.getLocalIndex("level")));
  -     il.append(IALOAD);
  -     il.append(IRETURN);
  -
  -     sortType.stripAttributes(true);
  -     sortType.setMaxLocals();
  -     sortType.setMaxStack();
  -     sortType.removeNOPs();
  -
  -     return sortType.getMethod();
  -    }
  -
  -
  -    /**
  -     * Compiles a method that overloads NodeSortRecord
  -     */
  -    private static Method compileSortOrder(Vector sortObjects,
  -                                        NodeSortRecordGenerator sortRecord,
  -                                        ConstantPoolGen cpg,
  -                                        String className) {
  -     final InstructionList il = new InstructionList();
  -     
  -     // int NodeSortRecord.sortOrder(level);
  -     final MethodGenerator sortOrder =
  -         new MethodGenerator(ACC_PUBLIC | ACC_FINAL,
  -                             de.fub.bytecode.generic.Type.INT, 
  -                             new de.fub.bytecode.generic.Type[] {
  -                                 de.fub.bytecode.generic.Type.INT
  -                             },
  -                             new String[] { "level" },
  -                             "sortOrder", className, il, cpg);
  -     final int idx = cpg.addFieldref(className, "_sortOrder", "[I");
  -     il.append(new GETSTATIC(idx));
  -     il.append(new ILOAD(sortOrder.getLocalIndex("level")));
  -     il.append(IALOAD);
  -     il.append(IRETURN);
  -
  -     sortOrder.stripAttributes(true);
  -     sortOrder.setMaxLocals();
  -     sortOrder.setMaxStack();
  -     sortOrder.removeNOPs();
  -
  -     return sortOrder.getMethod();
       }
   
       /**
  
  
  
  1.2       +10 -23    
xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java
  
  Index: NodeSortRecord.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSortRecord.java       2001/04/17 18:52:34     1.1
  +++ NodeSortRecord.java       2001/07/23 15:24:00     1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: NodeSortRecord.java,v 1.1 2001/04/17 18:52:34 sboag Exp $
  + * @(#)$Id: NodeSortRecord.java,v 1.2 2001/07/23 15:24:00 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -82,13 +82,15 @@
       public static int COMPARE_DESCENDING = 1;
   
       protected static Collator _collator = Collator.getInstance();
  +    protected static int[] _compareType;
  +    protected static int[] _sortOrder;
  +    protected static int _levels = 1;
   
       private Translet _translet = null;
       private DOM    _dom = null;
       private int    _node;           // The position in the current iterator
       private int    _last = 0;       // Number of nodes in the current 
iterator
  -    private int    _levels = 1;     // The number of sort keys for each 
element
  -    private int    _scanned = 0;
  +    private int    _scanned = 0;    // Number of key levels extracted from 
DOM
   
       private Object[] _values; // Contains either CollationKey or Double
   
  @@ -110,16 +112,14 @@
        * This method allows the caller to set the values that could not be 
passed
        * to the default constructor.
        */
  -    public final void initialize(int node, int last, int levels, DOM dom,
  -                              Translet translet) {
  +    public final void initialize(int node,int last,DOM dom,Translet 
translet) {
        _dom = dom;
        _node = node;
        _last = last;
  -     _levels = levels;
        _translet = translet;
        _scanned = 0;
   
  -     _values = new Object[levels];
  +     _values = new Object[_levels];
       }
   
       /**
  @@ -185,7 +185,7 @@
        int cmp, level;
        for (level = 0; level < _levels; level++) {
            // Compare the two nodes either as numeric or text values
  -         if (compareType(level) == COMPARE_NUMERIC) {
  +         if (_compareType[level] == COMPARE_NUMERIC) {
                final Double our = numericValue(level);
                final Double their = other.numericValue(level);
                cmp = our.compareTo(their);
  @@ -198,7 +198,7 @@
            
            // Return inverse compare value if inverse sort order
            if (cmp != 0) {
  -             return sortOrder(level) == COMPARE_DESCENDING ? 0 - cmp : cmp;
  +             return _sortOrder[level] == COMPARE_DESCENDING ? 0 - cmp : cmp;
            }
        }
        // Compare based on document order if all sort keys are equal
  @@ -214,22 +214,9 @@
       }
   
       /**
  -     * Returns compare type for a level of this key.
  -     * Must return either COMPARE_STRING or COMPARE_NUMERIC.
  -     */
  -    public abstract int compareType(int level);
  -
  -    /**
  -     * Returns sort order for a level of this key.
  -     * Most return either COMPARE_ASCENDING or COMPARE_DESCENDING.
  -     */
  -    public abstract int sortOrder(int level);
  -
  -    /**
        * Extract the sort value for a level of this key.
        */
       public abstract String extractValueFromDOM(DOM dom, int current, int 
level,
  -                                            Translet translet,
  -                                            int last);
  +                                            Translet translet, int last);
   
   }
  
  
  
  1.2       +7 -38     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java
  
  Index: NodeSortRecordFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeSortRecordFactory.java        2001/04/17 18:52:34     1.1
  +++ NodeSortRecordFactory.java        2001/07/23 15:24:00     1.2
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: NodeSortRecordFactory.java,v 1.1 2001/04/17 18:52:34 sboag Exp $
  + * @(#)$Id: NodeSortRecordFactory.java,v 1.2 2001/07/23 15:24:00 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -73,23 +73,20 @@
       private final Class    _class;
       private final String   _className;
       private final Translet _translet;
  -    private final int      _levels;
   
       /**
        * Creates a NodeSortRecord producing object. The DOM specifies which 
tree
        * to get the nodes to sort from, the class name specifies what auxillary
        * class to use to sort the nodes (this class is generated by the Sort
  -     * class), the level parameters specifies how many keys to sort on and 
the
  -     * translet parameter is needed for methods called by this object.
  +     * class), and the translet parameter is needed for methods called by
  +     * this object.
        */
  -    public NodeSortRecordFactory(DOM dom, String className, int levels,
  -                              Translet translet)
  +    public NodeSortRecordFactory(DOM dom, String className, Translet 
translet)
        throws TransletException {
        try {
            _dom = dom;
            _className = className;
            _class = Class.forName(className);
  -         _levels = levels;
            _translet = translet;
        }
        catch (ClassNotFoundException e) {
  @@ -107,40 +104,12 @@
               IllegalAccessException,
               InstantiationException,
               SecurityException,
  -            TransletException
  -    {
  -     // try {
  +            TransletException {
  +
        final NodeSortRecord sortRecord =
            (NodeSortRecord)_class.newInstance();
  -     sortRecord.initialize(node, last, _levels, _dom, _translet);
  +     sortRecord.initialize(node, last, _dom, _translet);
        return sortRecord;
  -     /*
  -        }
  -     catch (ExceptionInInitializerError e) {
  -         throw new TransletException("Could not initialize class " +
  -                                     _factory.getClassName());
  -     }
  -     catch (LinkageError e) {
  -         throw new TransletException("Could not link class " +
  -                                     _factory.getClassName());
  -     }
  -     catch (IllegalAccessException e) {
  -         throw new TransletException("Could not access class " +
  -                                     _factory.getClassName());
  -     }
  -     catch (InstantiationException e) {
  -         throw new TransletException("Could not instantiate class " +
  -                                     _factory.getClassName());
  -     }
  -     catch (SecurityException e) {
  -         throw new TransletException("Security break when accessing " +
  -                                     _factory.getClassName());
  -     }
  -     catch (Exception e) {
  -         throw new TransletException("Could not load class " +
  -                                     _factory.getClassName());
  -     }
  -     */
       }
   
       public String getClassName() {
  
  
  

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

Reply via email to