diff options
author | kitfox | 2010-03-24 15:11:43 +0100 |
---|---|---|
committer | kitfox | 2010-03-24 15:11:43 +0100 |
commit | d4fc813759a82a75ff0a709510ac9308ee70ccd2 (patch) | |
tree | f37e5f11fc51b882910893dfbc8744c38b79ac0f | |
parent | XMLParseUtil can now handle unitless coordinates. (diff) | |
download | svg-salamander-core-d4fc813759a82a75ff0a709510ac9308ee70ccd2.tar.gz svg-salamander-core-d4fc813759a82a75ff0a709510ac9308ee70ccd2.tar.xz svg-salamander-core-d4fc813759a82a75ff0a709510ac9308ee70ccd2.zip |
Optimized SVGUniverse to cache XMLReader, not create SAXReader.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@74 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rw-r--r-- | src/main/java/com/kitfox/svg/SVGUniverse.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/com/kitfox/svg/SVGUniverse.java b/src/main/java/com/kitfox/svg/SVGUniverse.java index c48a9e7..8fdf19d 100644 --- a/src/main/java/com/kitfox/svg/SVGUniverse.java +++ b/src/main/java/com/kitfox/svg/SVGUniverse.java @@ -54,6 +54,7 @@ import javax.imageio.ImageIO; import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
@@ -93,6 +94,9 @@ public class SVGUniverse implements Serializable protected double curTime = 0.0;
private boolean verbose = false;
+
+ //Cache reader for efficiency
+ XMLReader cachedReader;
/** Creates a new instance of SVGUniverse */
public SVGUniverse()
@@ -468,6 +472,14 @@ public class SVGUniverse implements Serializable }
}
+ private XMLReader getXMLReaderCached() throws SAXException
+ {
+ if (cachedReader == null)
+ {
+ cachedReader = XMLReaderFactory.createXMLReader();
+ }
+ return cachedReader;
+ }
// protected URI loadSVG(URI xmlBase, InputStream is)
protected URI loadSVG(URI xmlBase, InputSource is)
@@ -482,14 +494,14 @@ public class SVGUniverse implements Serializable loadedDocs.put(xmlBase, handler.getLoadedDiagram());
// Use the default (non-validating) parser
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(true);
+// SAXParserFactory factory = SAXParserFactory.newInstance();
+// factory.setValidating(false);
+// factory.setNamespaceAware(true);
try
{
// Parse the input
- XMLReader reader = XMLReaderFactory.createXMLReader();
+ XMLReader reader = getXMLReaderCached();
reader.setEntityResolver(
new EntityResolver()
{
|