Further performance optimalizations. Tasklist module TODOs are scanned in 15sec (instead of original 60sec), NB seach makes it in 39sec, linux native grep utility in 5sec.
1.1 --- a/o.n.tasklistapi/build.xml Tue Dec 30 22:55:32 2003 +0000
1.2 +++ b/o.n.tasklistapi/build.xml Sat Jan 03 21:49:55 2004 +0000
1.3 @@ -31,6 +31,7 @@
1.4 <include name="openide*.jar" />
1.5 </fileset>
1.6 <pathelement location="${nb_all}/openide/loaders/netbeans/lib/openide-loaders.jar"/>
1.7 + <pathelement location="${nb_all}/java/netbeans/modules/java.jar"/> <!-- Hard compile-time, soft run-time dependency -->
1.8 </path>
1.9
1.10 <target name="compile">
2.1 --- a/o.n.tasklistapi/manifest.mf Tue Dec 30 22:55:32 2003 +0000
2.2 +++ b/o.n.tasklistapi/manifest.mf Sat Jan 03 21:49:55 2004 +0000
2.3 @@ -5,5 +5,6 @@
2.4 OpenIDE-Module-IDE-Dependencies: IDE/1 > 4.11
2.5 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/tasklist/client/Bundle.properties
2.6 OpenIDE-Module-Layer: org/netbeans/apihole/tasklist/mf-layer.xml
2.7 +OpenIDE-Module-Module-Dependencies: org.netbeans.modules.java/1 > 1.16
2.8 OpenIDE-Module-Public-Packages: -
2.9 X-OpenIDE-Module-Public-Packages: org.netbeans.api.tasklist.*,org.netbeans.spi.tasklist.*
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/o.n.tasklistapi/src/org/netbeans/modules/tasklist/providers/JavaSuggestionContext.java Sat Jan 03 21:49:55 2004 +0000
3.3 @@ -0,0 +1,39 @@
3.4 +/*
3.5 + * Sun Public License Notice
3.6 + *
3.7 + * The contents of this file are subject to the Sun Public License
3.8 + * Version 1.0 (the "License"). You may not use this file except in
3.9 + * compliance with the License. A copy of the License is available at
3.10 + * http://www.sun.com/
3.11 + *
3.12 + * The Original Code is NetBeans. The Initial Developer of the Original
3.13 + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
3.14 + * Microsystems, Inc. All Rights Reserved.
3.15 + */
3.16 +
3.17 +package org.netbeans.modules.tasklist.providers;
3.18 +
3.19 +import org.openide.filesystems.FileObject;
3.20 +import org.openide.ErrorManager;
3.21 +
3.22 +import java.io.IOException;
3.23 +
3.24 +/**
3.25 + * Dedicated java source context that is faster than generic one.
3.26 + *
3.27 + * @author Petr Kuzel
3.28 + */
3.29 +final class JavaSuggestionContext {
3.30 +
3.31 + static String getContent(FileObject fo) {
3.32 + String encoding = org.netbeans.modules.java.Util.getFileEncoding(fo);
3.33 + char[] source = null;
3.34 + try {
3.35 + source = org.netbeans.modules.java.Util.getContent(fo, false, true, encoding);
3.36 + return new String(source);
3.37 + } catch (IOException e) {
3.38 + ErrorManager.getDefault().notify(e);
3.39 + }
3.40 + return null;
3.41 + }
3.42 +}
4.1 --- a/o.n.tasklistapi/src/org/netbeans/modules/tasklist/providers/SuggestionContext.java Tue Dec 30 22:55:32 2003 +0000
4.2 +++ b/o.n.tasklistapi/src/org/netbeans/modules/tasklist/providers/SuggestionContext.java Sat Jan 03 21:49:55 2004 +0000
4.3 @@ -16,6 +16,7 @@
4.4 import org.openide.loaders.DataObject;
4.5 import org.openide.cookies.EditorCookie;
4.6 import org.openide.filesystems.FileObject;
4.7 +import org.openide.ErrorManager;
4.8
4.9 import javax.swing.text.Document;
4.10 import javax.swing.text.BadLocationException;
4.11 @@ -35,6 +36,9 @@
4.12
4.13 private String cachedString;
4.14
4.15 + // we have soft runtime dependency on java module
4.16 + private static boolean linkageError;
4.17 +
4.18 /**
4.19 * For internal framework purposes only!
4.20 */
4.21 @@ -46,22 +50,33 @@
4.22 * @return read-only snapshot of context representation
4.23 */
4.24 public CharSequence getCharSequence() {
4.25 +
4.26 if (cachedString == null) {
4.27 +
4.28 + FileObject fo = getFileObject();
4.29 + if (linkageError == false && fo.hasExt("java")) { // NOI18N
4.30 + // use faster direct access to file for java sources
4.31 + // I measured 10% speedup
4.32 + try {
4.33 + // XXX it does not normalize line separators to \n
4.34 + cachedString = JavaSuggestionContext.getContent(fo);
4.35 + return cachedString;
4.36 + } catch (LinkageError link) {
4.37 + // use EditorCookie below
4.38 + link.printStackTrace();
4.39 + linkageError = true;
4.40 + }
4.41 + }
4.42 +
4.43 EditorCookie edit =
4.44 (EditorCookie) dataObject.getCookie(EditorCookie.class);
4.45 if (edit != null) {
4.46 Document doc;
4.47 - // XXX if not opened it could be faster to
4.48 - // take FileChannel and read it into CharBuffer.
4.49 - // It has several drawbacks: guarded blocks makers are not filtered
4.50 - // out, no line normalization is made, encoding must
4.51 - // be heuritically guessed....
4.52 try {
4.53 doc = edit.openDocument(); // DOES block
4.54 cachedString = extractString(doc);
4.55 } catch (IOException e) {
4.56 - // XXX
4.57 - e.printStackTrace();
4.58 + ErrorManager.getDefault().notify(e);
4.59 }
4.60 }
4.61 }
5.1 --- a/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionList.java Tue Dec 30 22:55:32 2003 +0000
5.2 +++ b/suggestions_framework/src/org/netbeans/modules/tasklist/suggestions/SuggestionList.java Sat Jan 03 21:49:55 2004 +0000
5.3 @@ -119,7 +119,8 @@
5.4 Iterator it = tasks.iterator();
5.5 while (it.hasNext()) {
5.6 SuggestionImpl s = (SuggestionImpl)it.next();
5.7 - if (s.getSType().getPosition() >= pos) {
5.8 + int spos = s.getSType().getPosition();
5.9 + if (spos > pos) {
5.10 break;
5.11 } else {
5.12 after = s;
6.1 --- a/tasklist.docscan/src/org/netbeans/modules/tasklist/docscan/SourceCodeCommentParser.java Tue Dec 30 22:55:32 2003 +0000
6.2 +++ b/tasklist.docscan/src/org/netbeans/modules/tasklist/docscan/SourceCodeCommentParser.java Sat Jan 03 21:49:55 2004 +0000
6.3 @@ -18,11 +18,7 @@
6.4
6.5 import org.netbeans.modules.tasklist.providers.SuggestionContext;
6.6
6.7 -import java.io.BufferedReader;
6.8 -import java.io.File;
6.9 -import java.io.FileReader;
6.10 -import java.io.IOException;
6.11 -import java.io.StringReader;
6.12 +import java.io.*;
6.13
6.14
6.15 /**
6.16 @@ -79,19 +75,7 @@
6.17 public void setDocument(SuggestionContext env) {
6.18 parser.setDocument(env);
6.19 }
6.20 -
6.21 - /**
6.22 - * Set the document to parse
6.23 - * @param doc the document to parse
6.24 - * @throws java.io.IOException if anything goes wrong...
6.25 - *
6.26 - * XXX not used however the idea is smart, do we really need
6.27 - * Document interface from the framework?
6.28 - */
6.29 - public void setDocument(File f) throws IOException {
6.30 - parser.setDocument(f);
6.31 - }
6.32 -
6.33 +
6.34 /**
6.35 * get the next line of text from the file
6.36 * @param ret Where to store the result
6.37 @@ -117,8 +101,9 @@
6.38 * Create a new instance of the SourceParser
6.39 */
6.40 public SourceParser() {
6.41 - doc = null;
6.42 + chars = null;
6.43 lineno = 0;
6.44 + pos = 0;
6.45 rest = null;
6.46 inComment = false;
6.47 }
6.48 @@ -131,38 +116,56 @@
6.49 * stream.
6.50 */
6.51 public boolean getNextLine(CommentLine ret) throws IOException {
6.52 - ret.line = doc.readLine();
6.53 + ret.line = readLine();
6.54 ++lineno;
6.55 ret.lineno = lineno;
6.56 return ret.line != null;
6.57 }
6.58 -
6.59 +
6.60 + /*
6.61 + * 'Tokenizes' charsequence at \n, \r\n and \r boundaries.
6.62 + */
6.63 + protected final String readLine() {
6.64 + StringBuffer sb = new StringBuffer(83);
6.65 + if (pos >= chars.length()) return null;
6.66 + while (pos < chars.length()) {
6.67 + char ch = chars.charAt(pos);
6.68 + if (ch == '\r') {
6.69 + if (chars.charAt(pos +1) == '\n') {
6.70 + pos+=2;
6.71 + break;
6.72 + } else {
6.73 + pos++;
6.74 + break;
6.75 + }
6.76 + } else if (ch == '\n') {
6.77 + pos++;
6.78 + break;
6.79 + } else {
6.80 + sb.append(ch);
6.81 + pos++;
6.82 + }
6.83 + }
6.84 + return sb.toString();
6.85 + }
6.86 +
6.87 /**
6.88 * Set the document to parse
6.89 - * @param doc the document to parse
6.90 + * @param env to parse
6.91 */
6.92 public void setDocument(SuggestionContext env) {
6.93 - String text = (String) env.getCharSequence(); //XXX downcast
6.94 - this.doc = new BufferedReader(new StringReader(text));
6.95 + this.chars = env.getCharSequence();
6.96 lineno = 0;
6.97 + pos = 0;
6.98 rest = null;
6.99 inComment = false;
6.100 }
6.101
6.102 - /**
6.103 - * Set the document to parse
6.104 - * @param doc the document to parse
6.105 - */
6.106 - public void setDocument(File f) throws IOException {
6.107 - this.doc = new BufferedReader(new FileReader(f));
6.108 - lineno = 0;
6.109 - rest = null;
6.110 - inComment = false;
6.111 - }
6.112 -
6.113 -
6.114 /** The reader I use to read the document content from */
6.115 - protected BufferedReader doc;
6.116 + private CharSequence chars;
6.117 +
6.118 + private int pos; // position in above sequence
6.119 +
6.120 /** Current line in the file */
6.121 protected int lineno;
6.122 /**
6.123 @@ -215,7 +218,7 @@
6.124 String line = null;
6.125
6.126 // Read next line of input!
6.127 - while (rest != null || (line = doc.readLine()) != null) {
6.128 + while (rest != null || (line = readLine()) != null) {
6.129 if (rest != null) {
6.130 line = rest;
6.131 rest = null;
7.1 --- a/tasklist.html/src/org/netbeans/modules/tasklist/html/TidySuggester.java Tue Dec 30 22:55:32 2003 +0000
7.2 +++ b/tasklist.html/src/org/netbeans/modules/tasklist/html/TidySuggester.java Sat Jan 03 21:49:55 2004 +0000
7.3 @@ -132,8 +132,11 @@
7.4 parseObject = dobj;
7.5 if (manager.isEnabled(TYPE)) {
7.6 InputStream input = null;
7.7 - String text = (String) env.getCharSequence(); //XXX downcast, InputStream from FileObject
7.8 - input = new StringBufferInputStream(text);
7.9 + try {
7.10 + input = env.getFileObject().getInputStream();
7.11 + } catch (FileNotFoundException e) {
7.12 + return null;
7.13 + }
7.14
7.15 if (tidy == null) {
7.16 tidy = new Tidy();