User: vharcq  
  Date: 02/04/03 06:31:42

  Modified:    src/xjavadoc AbstractClass.java
                        AbstractExecutableMember.java
                        AbstractProgramElement.java MethodImpl.java
                        ProxyClass.java SourceClass.java XDoc.java
  Log:
  Performance changes
  Small on samples but on my own project it runs now in half the time !
  
  Revision  Changes    Path
  1.16      +7 -5      xjavadoc/src/xjavadoc/AbstractClass.java
  
  Index: AbstractClass.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractClass.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -r1.15 -r1.16
  --- AbstractClass.java        26 Mar 2002 00:16:41 -0000      1.15
  +++ AbstractClass.java        3 Apr 2002 14:31:42 -0000       1.16
  @@ -452,12 +452,14 @@
         */
        public final XMethod[] methods() {
                complete();
  +             if (_xmethods == null) {
                if (_methods == null) {
  -                     return ZERO_METHODS;
  +                             _xmethods = new XMethod[0];
                }
  -             if (_xmethods == null) {
  +                     else {
                        _xmethods = new XMethod[_methods.size()];
                        _xmethods = (XMethod[])_methods.toArray(_xmethods);
  +                     }
                }
                return _xmethods;
        }
  
  
  
  1.7       +51 -20    xjavadoc/src/xjavadoc/AbstractExecutableMember.java
  
  Index: AbstractExecutableMember.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractExecutableMember.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- AbstractExecutableMember.java     26 Mar 2002 19:49:41 -0000      1.6
  +++ AbstractExecutableMember.java     3 Apr 2002 14:31:42 -0000       1.7
  @@ -59,6 +59,26 @@
        /**
         * @todo-javadoc Describe the field
         */
  +     private String nameWithSignature;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private String signature;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private XClass[] thrownExceptions;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private XParameter[] parameters;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
        private final static XParameter[] EMPTY_PARAMETERS = new XParameter[0];
   
        /**
  @@ -155,23 +175,24 @@
         * @return the method parameters
         */
        public final XParameter[] parameters() {
  -             XParameter[] result = null;
  +             if (parameters == null) {
                if (_parameterData == null) {
  -                     result = EMPTY_PARAMETERS;
  +                             parameters = EMPTY_PARAMETERS;
                }
                else {
  -                     result = new ParameterImpl[_parameterData.size() / 3];
  -                     for (int i = result.length - 1; i >= 0; i--) {
  +                             parameters = new ParameterImpl[_parameterData.size() / 
3];
  +                             for (int i = parameters.length - 1; i >= 0; i--) {
                                try {
                                        _parameterPool[i].setState(this, i);
                                        // TODO increase pool size
  -                                     result[i] = _parameterPool[i];
  +                                             parameters[i] = _parameterPool[i];
                                } catch (ArrayIndexOutOfBoundsException e) {
                                        System.out.println("In member " + 
qualifiedName() + ". Tried to set " + i + "th parameter. FIXME!");
                                }
                        }
                }
  -             return result;
  +             }
  +             return parameters;
        }
   
   
  @@ -183,11 +204,13 @@
         * @todo-javadoc Write javadocs for return value
         */
        public XClass[] thrownExceptions() {
  -             XClass[] thrownExceptions = new XClass[_thrownExceptions.size()];
  +             if (thrownExceptions == null) {
  +                     thrownExceptions = new XClass[_thrownExceptions.size()];
                for (int i = 0; i < thrownExceptions.length; i++) {
                        String exceptionName = (String)_thrownExceptions.get(i);
                        thrownExceptions[i] = containingClass().qualify(exceptionName);
                }
  +             }
                return thrownExceptions;
        }
   
  @@ -212,7 +235,10 @@
         * @todo-javadoc Write javadocs for return value
         */
        public final String signature() {
  -             return signature(new StringBuffer());
  +             if (signature == null) {
  +                     signature = signature(new StringBuffer());
  +             }
  +             return signature;
        }
   
   
  @@ -224,7 +250,10 @@
         * @todo-javadoc Write javadocs for return value
         */
        public final String nameWithSignature() {
  -             return signature(new StringBuffer(name()));
  +             if (nameWithSignature == null) {
  +                     nameWithSignature = signature(new StringBuffer(name()));
  +             }
  +             return nameWithSignature;
        }
   
   
  @@ -336,11 +365,13 @@
                }
                return sb.toString();
        }
  +
        static {
                for (int i = 0; i < MAX_ARRAY_SIZE; i++) {
                        _dimensions[i] = new Integer(i);
                }
        }
  +
        static {
                for (int i = 0; i < PARAMETER_POOL_SIZE; i++) {
                        _parameterPool[i] = new ParameterImpl();
  
  
  
  1.9       +44 -31    xjavadoc/src/xjavadoc/AbstractProgramElement.java
  
  Index: AbstractProgramElement.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/AbstractProgramElement.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- AbstractProgramElement.java       16 Mar 2002 19:26:04 -0000      1.8
  +++ AbstractProgramElement.java       3 Apr 2002 14:31:42 -0000       1.9
  @@ -68,6 +68,11 @@
        private int _modifiers = 0;
   
        /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private String modifiers;
  +
  +     /**
         * @todo refactor
         */
        private XDoc _doc;
  @@ -81,6 +86,11 @@
         */
        private Token _javadocToken;
   
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private final XDoc NULL_XDOC = new XDoc(null, this);
  +
   
        /**
         * Describe what the AbstractProgramElement constructor does
  @@ -262,14 +272,12 @@
         * @return the class level doc
         */
        public final XDoc doc() {
  +             if (_doc == null) {
                if (_token == null) {
                        // We're not from source (we're binary, primitive or unknown)
  -                     return new XDoc(null, this);
  +                             _doc = NULL_XDOC;
                }
  -             if (_doc != null) {
  -                     return _doc;
  -             }
  -
  +                     else {
                if (_javadocToken != null) {
                        _doc = new XDoc(_javadocToken, this);
                }
  @@ -293,6 +301,8 @@
                        _token.specialToken = preJavadocToken;
                        _doc = new XDoc(_javadocToken, this);
                }
  +                     }
  +             }
                return _doc;
        }
   
  @@ -304,7 +314,10 @@
         * @todo-javadoc Write javadocs for return value
         */
        public final String modifiers() {
  -             return Modifier.toString(_modifiers);
  +             if (modifiers == null) {
  +                     modifiers = Modifier.toString(_modifiers);
  +             }
  +             return modifiers;
        }
   
   
  
  
  
  1.7       +30 -13    xjavadoc/src/xjavadoc/MethodImpl.java
  
  Index: MethodImpl.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/MethodImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -w -r1.6 -r1.7
  --- MethodImpl.java   26 Mar 2002 19:49:41 -0000      1.6
  +++ MethodImpl.java   3 Apr 2002 14:31:42 -0000       1.7
  @@ -58,6 +58,16 @@
        /**
         * @todo-javadoc Describe the field
         */
  +     private String toString;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private String dimensionAsString;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
        public static int instanceCount = 0;
   
   
  @@ -139,7 +149,9 @@
         * @todo-javadoc Write javadocs for return value
         */
        public String toString() {
  +             if (toString == null) {
                StringBuffer sb = new StringBuffer();
  +                     sb = new StringBuffer();
                sb.append(modifiers());
                sb.append(" ");
                sb.append(returnType());
  @@ -147,7 +159,9 @@
                sb.append(" ");
                sb.append(name());
                sb.append(signature());
  -             return sb.toString();
  +                     toString = sb.toString();
  +             }
  +             return toString;
        }
   
   
  @@ -159,11 +173,14 @@
         * @todo-javadoc Write javadocs for return value
         */
        public String returnDimensionAsString() {
  +             if (dimensionAsString == null) {
                StringBuffer sb = new StringBuffer();
                for (int i = returnDimension() - 1; i >= 0; i--) {
                        sb.append("[]");
                }
  -             return sb.toString();
  +                     dimensionAsString = sb.toString();
  +             }
  +             return dimensionAsString;
        }
   
   
  
  
  
  1.16      +3 -1      xjavadoc/src/xjavadoc/ProxyClass.java
  
  Index: ProxyClass.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ProxyClass.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -r1.15 -r1.16
  --- ProxyClass.java   26 Mar 2002 00:16:41 -0000      1.15
  +++ ProxyClass.java   3 Apr 2002 14:31:42 -0000       1.16
  @@ -426,7 +426,9 @@
         * @todo-javadoc Write javadocs for return value
         */
        public XMethod[] methods() {
  +             if (_subject == null) {
                resolve();
  +             }
                return _subject.methods();
        }
   
  
  
  
  1.19      +8 -9      xjavadoc/src/xjavadoc/SourceClass.java
  
  Index: SourceClass.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/SourceClass.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -w -r1.18 -r1.19
  --- SourceClass.java  26 Mar 2002 06:00:50 -0000      1.18
  +++ SourceClass.java  3 Apr 2002 14:31:42 -0000       1.19
  @@ -325,23 +325,22 @@
         * @todo-javadoc Write javadocs for return value
         */
        protected void complete() {
  -             if (isOuterClass()) {
                        if (!_isParseCompleted) {
  -
  +                     if (isOuterClass()) {
                                // wake up the waiting parser thread
  -                             _log.debug("in " + qualifiedName() + "'s complete(). 
entering sync");
  +                             //_log.debug("in " + qualifiedName() + "'s complete(). 
entering sync");
                                synchronized (getParseLock()) {
  -                                     _log.debug("in " + qualifiedName() + "'s 
complete(). inside sync");
  +                                     //_log.debug("in " + qualifiedName() + "'s 
complete(). inside sync");
                                        getParseLock().notify();
  -                                     _log.debug("notified parser in 
notifyAndWait()");
  +                                     //_log.debug("notified parser in 
notifyAndWait()");
   
                                        /// and wait until it's done with the rest
                                        try {
  -                                             _log.debug("waiting for parser to 
complete in complete()");
  +                                             //_log.debug("waiting for parser to 
complete in complete()");
                                                getParseLock().wait();
  -                                             _log.debug("notified by completed 
parser in complete()");
  +                                             //_log.debug("notified by completed 
parser in complete()");
                                        } catch (InterruptedException e) {
  -                                             _log.debug("The complete() of " + 
qualifiedName() + " has been interrupted");
  +                                             //_log.debug("The complete() of " + 
qualifiedName() + " has been interrupted");
                                        }
   
                                        _isParseCompleted = true;
  
  
  
  1.23      +76 -36    xjavadoc/src/xjavadoc/XDoc.java
  
  Index: XDoc.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/XDoc.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -w -r1.22 -r1.23
  --- XDoc.java 3 Apr 2002 12:30:54 -0000       1.22
  +++ XDoc.java 3 Apr 2002 14:31:42 -0000       1.23
  @@ -46,6 +46,8 @@
   import java.util.ArrayList;
   import java.util.Arrays;
   import java.util.StringTokenizer;
  +import java.util.Map;
  +import java.util.Hashtable;
   
   import xjavadoc.XTag;
   import xjavadoc.Token;
  @@ -70,7 +72,7 @@
         * Maps tag name to List. The List contains XTag instances whose name = name
         * (the map key)
         */
  -     private final HashMap _tagMap = new HashMap();
  +     private final Hashtable _tagMap = new Hashtable();
   
        /**
         * List that holds all the tags of this doc.
  @@ -80,6 +82,11 @@
        /**
         * @todo-javadoc Describe the field
         */
  +     private XTag[] tagArray = null;
  +
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
        private boolean _dirty = true;
   
        /**
  @@ -117,6 +124,11 @@
         */
        private static org.apache.log4j.Category _log = 
org.apache.log4j.Category.getInstance(XDoc.class.getName());
   
  +     /**
  +      * @todo-javadoc Describe the field
  +      */
  +     private final static String EMPTY_COMMENT = "/**\n */";
  +
   
        /**
         * Describe what the XDoc constructor does
  @@ -140,7 +152,7 @@
                _owner = owner;
                if (_javadocToken.image == null) {
                        // the passed token was not from source code, but was created 
because no javadoc existed.
  -                     _javadocToken.image = "/**\n */";
  +                     _javadocToken.image = EMPTY_COMMENT;
                }
        }
   
  @@ -331,7 +343,9 @@
         * @todo-javadoc Write javadocs for method parameter
         */
        public XTag tag(String tagName, boolean superclasses) {
  +             if (_dirty) {
                parse();
  +             }
                XTag[] tags = tags(tagName, superclasses);
                if (tags.length == 0) {
                        return null;
  @@ -434,7 +448,9 @@
         * @return a String representation of this doc.
         */
        public String toString() {
  +             if (_dirty) {
                parse();
  +             }
                StringBuffer sb = new StringBuffer("/**").append(NEWLINE);
                if (!_commentText.trim().equals("")) {
                        appendWhiteSpaces(sb).append(" * 
").append(_commentText).append(NEWLINE);
  @@ -469,7 +485,9 @@
         * @todo-javadoc Write javadocs for return value
         */
        public String commentText() {
  +             if (_dirty) {
                parse();
  +             }
                return _commentText;
        }
   
  @@ -482,7 +500,9 @@
         * @todo-javadoc Write javadocs for return value
         */
        public String firstSentence() {
  +             if (_dirty) {
                parse();
  +             }
                int dotIndex = _commentText.indexOf(".");
                if (dotIndex != -1) {
                        return _commentText.substring(0, dotIndex) + ".";
  @@ -501,9 +521,13 @@
         * @todo-javadoc Write javadocs for return value
         */
        public XTag[] tags() {
  +             if (_dirty) {
                parse();
  -             XTag[] tagArray = new XTag[_allTags.size()];
  -             return (XTag[])_allTags.toArray(tagArray);
  +             }
  +             if (tagArray == null) {
  +                     tagArray = (XTag[])_allTags.toArray(new XTag[_allTags.size()]);
  +             }
  +             return tagArray;
        }
   
   
  @@ -516,25 +540,17 @@
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for return value
         */
  -     public XTag[] tags(String tagName) {
  +     public XTag[] tags(final String tagName) {
  +             if (_dirty) {
                parse();
  -             ArrayList tags = (ArrayList)_tagMap.get(tagName);
  -
  -             if (tags == null) {
  -                     String dottedFormatTagName = tagName.replace(':', '.');
  -                     tags = (ArrayList)_tagMap.get(dottedFormatTagName);
  -             }
  -             if (tags == null) {
  -                     String colonedFormatTagName = tagName.replace('.', ':');
  -                     tags = (ArrayList)_tagMap.get(colonedFormatTagName);
                }
  +             XTag[] tags = (XTag[])_tagMap.get(dotted(tagName));
   
                if (tags == null) {
                        return new XTag[0];
                }
                else {
  -                     XTag[] tagArray = new XTag[tags.size()];
  -                     return (XTag[])tags.toArray(tagArray);
  +                     return tags;
                }
        }
   
  @@ -591,7 +607,9 @@
         * @todo-javadoc Write javadocs for return value
         */
        private XTag addTag(String tagName, String text) {
  +             if (_dirty) {
                parse();
  +             }
                return addTag_Impl(tagName, text);
        }
   
  @@ -607,15 +625,18 @@
         * @todo-javadoc Describe the method parameter
         * @todo-javadoc Describe the method parameter
         */
  -     private XTag addTag_Impl(String tagName, String text) {
  -             ArrayList tags = (ArrayList)_tagMap.get(tagName);
  +     private XTag addTag_Impl(final String tagName, String text) {
  +             XTag[] tags = (XTag[])_tagMap.get(dotted(tagName));
  +             List tagsList;
                if (tags == null) {
  -                     tags = new ArrayList();
  -                     _tagMap.put(tagName, tags);
  +                     tagsList = new ArrayList();
  +             }
  +             else {
  +                     tagsList = new ArrayList(Arrays.asList(tags));
                }
                XTag tag = XTagFactory.getInstance().createTag(tagName, text);
  -             tags.add(tag);
  -             _allTags.add(tag);
  +             tagsList.add(tag);
  +             _tagMap.put(dotted(tagName), tagsList.toArray(new 
XTag[tagsList.size()]));
                return tag;
        }
   
  @@ -667,6 +688,7 @@
         * @todo-javadoc Write javadocs for method parameter
         */
        private void parse() {
  +             if (_dirty) {
                //_log.debug("parse");
                // We must read line by line, since a @tags can only begin as the 
first token of a line.
                BufferedReader in = new BufferedReader(new JavaDocReader(new 
StringReader(_javadocToken.image)));
  @@ -674,7 +696,6 @@
                StringBuffer docElement = new StringBuffer();
                String tagName = null;
                String line = null;
  -             if (_dirty) {
                        try {
                                while ((line = in.readLine()) != null) {
                                        if (line.startsWith("@")) {
  @@ -717,6 +738,25 @@
                        }
                }
                _dirty = false;
  +     }
  +
  +
  +     /**
  +      * Describe what the method does
  +      *
  +      * @param tagName Describe what the parameter does
  +      * @return Describe the return value
  +      * @todo-javadoc Write javadocs for method
  +      * @todo-javadoc Write javadocs for method parameter
  +      * @todo-javadoc Write javadocs for return value
  +      */
  +     private String dotted(final String tagName) {
  +             if (tagName.indexOf('.') > -1) {
  +                     return tagName.replace('.', ':');
  +             }
  +             else {
  +                     return tagName;
  +             }
        }
   
   //   private final static boolean isTabOrSpace(String s) {
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to