Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2014-07-31 21:06:15 +0000
committerJeff Johnston2014-08-06 21:25:00 +0000
commitfd18d71252a8bbf541ecd93339e1cdac1713d85e (patch)
tree3d3c475e348f82e5fbc4417e772984efc1b85138 /libhover
parent00b2bd1539d430209783085c3ad0e2ef4f357541 (diff)
downloadorg.eclipse.linuxtools-fd18d71252a8bbf541ecd93339e1cdac1713d85e.tar.gz
org.eclipse.linuxtools-fd18d71252a8bbf541ecd93339e1cdac1713d85e.tar.xz
org.eclipse.linuxtools-fd18d71252a8bbf541ecd93339e1cdac1713d85e.zip
Make devhelp parser faster
- stop parsing file when we know we have our function info by throwing an exception - close the InputStream each time after parsing Change-Id: I1c41b7695b35561eeec687cd9e480d5bc53c597d Reviewed-on: https://git.eclipse.org/r/30832 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com>
Diffstat (limited to 'libhover')
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/ParseDevHelp.java63
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/preferences/FuncFoundSaxException.java22
2 files changed, 58 insertions, 27 deletions
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/ParseDevHelp.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/ParseDevHelp.java
index 47cd9748dc..03b35f05bd 100644
--- a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/ParseDevHelp.java
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/ParseDevHelp.java
@@ -41,6 +41,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.cdt.libhover.FunctionInfo;
import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo;
+import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.FuncFoundSaxException;
import org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences.LibHoverMessages;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
@@ -164,6 +165,7 @@ public class ParseDevHelp {
descStart = false;
parmStart = false;
protoStart = false;
+ throw new FuncFoundSaxException(); // indicate we are done and stop parser
}
}
if (descStart) {
@@ -381,33 +383,40 @@ public class ParseDevHelp {
}
private void parseLink(Node link, Node name, IPath path, LibHoverInfo libhover) {
- String linkValue = link.getNodeValue();
- String[] linkParts = linkValue.split("#"); //$NON-NLS-1$
- if (linkParts.length == 2) {
- try {
- String nameString = name.getNodeValue();
- nameString = nameString.replaceAll("\\(.*\\);+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
- if (nameString.contains("::") || nameString.startsWith("enum ") //$NON-NLS-1$ //$NON-NLS-2$
- || nameString.contains("\"")) { //$NON-NLS-1$
- return;
- }
- InputStream reader = new FileInputStream(path.removeLastSegments(1).toOSString()
- + "/" + linkParts[0]); //$NON-NLS-1$
- HTMLSaxParser parser = new HTMLSaxParser(linkParts[1], nameString);
- parser.parse(new InputSource(reader));
- FunctionInfo finfo = parser.getFunctionInfo();
- if (finfo != null) {
- if (debug) {
- System.out.println(parser.toString());
- }
- libhover.functions.put(parser.getFuncName(), parser.getFunctionInfo());
- }
- } catch (IOException e) {
- // ignore
- } catch (SAXException e) {
- e.printStackTrace();
- }
- }
+ String linkValue = link.getNodeValue();
+ String[] linkParts = linkValue.split("#"); //$NON-NLS-1$
+ InputStream reader = null;
+ HTMLSaxParser parser = null;
+ if (linkParts.length == 2) {
+ try {
+ String nameString = name.getNodeValue();
+ nameString = nameString.replaceAll("\\(.*\\);+", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
+ if (nameString.contains("::") || nameString.startsWith("enum ") //$NON-NLS-1$ //$NON-NLS-2$
+ || nameString.contains("\"")) { //$NON-NLS-1$
+ return;
+ }
+ reader = new FileInputStream(path.removeLastSegments(1).toOSString()
+ + "/" + linkParts[0]); //$NON-NLS-1$
+ parser = new HTMLSaxParser(linkParts[1], nameString);
+ try {
+ parser.parse(new InputSource(reader));
+ } catch (FuncFoundSaxException e) {
+ // ignore because this is just how we shorten parse time
+ }
+ reader.close();
+ FunctionInfo finfo = parser.getFunctionInfo();
+ if (finfo != null) {
+ if (debug) {
+ System.out.println(parser.toString());
+ }
+ libhover.functions.put(parser.getFuncName(), parser.getFunctionInfo());
+ }
+ } catch (IOException e) {
+ // ignore
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+ }
}
private void parse(String fileName, IProgressMonitor monitor) {
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/preferences/FuncFoundSaxException.java b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/preferences/FuncFoundSaxException.java
new file mode 100644
index 0000000000..ed4d74658d
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover.devhelp/src/org/eclipse/linuxtools/internal/cdt/libhover/devhelp/preferences/FuncFoundSaxException.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Inc. - Initial implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.devhelp.preferences;
+
+
+// This class is just to allow us to end parsing devhelp docs once
+// we have found the function we are interested in
+public class FuncFoundSaxException extends RuntimeException {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}

Back to the top