From b7336c47bd96457f49010efff87cf144d8e35894 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 27 Mar 2012 14:11:33 +0200 Subject: [PATCH] reuse exception instances for faster NanoXml (IDEA-83525) --- .../com/intellij/util/xml/NanoXmlUtil.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/platform/lang-api/src/com/intellij/util/xml/NanoXmlUtil.java b/platform/lang-api/src/com/intellij/util/xml/NanoXmlUtil.java index 69a277574074..05c7a864d9e4 100644 --- a/platform/lang-api/src/com/intellij/util/xml/NanoXmlUtil.java +++ b/platform/lang-api/src/com/intellij/util/xml/NanoXmlUtil.java @@ -98,6 +98,7 @@ public class NanoXmlUtil { } catch (XMLException e) { if (e.getException() instanceof ParserStoppedException) return; + if (e.getException() instanceof ParserStoppedXmlException) return; LOG.debug(e); } } @@ -203,8 +204,8 @@ public class NanoXmlUtil { return null; } - protected static void stop() { - throw new ParserStoppedException(); + protected static void stop() throws ParserStoppedXmlException { + throw ParserStoppedXmlException.INSTANCE; } } @@ -318,6 +319,22 @@ public class NanoXmlUtil { } } + public static class ParserStoppedXmlException extends XMLException { + public static final ParserStoppedException INSTANCE = new ParserStoppedException(); + + private ParserStoppedXmlException() { + super("Parsing stopped"); + } + + @Override + public Throwable fillInStackTrace() { + return this; + } + } + + /** + * @deprecated throw {@link ParserStoppedXmlException#INSTANCE} instead + */ public static class ParserStoppedException extends RuntimeException { @Override public Throwable fillInStackTrace() { @@ -338,7 +355,7 @@ public class NanoXmlUtil { public void startElement(final String name, final String nsPrefix, final String nsURI, final String systemID, final int lineNr) throws Exception { myRootTagName = name; myNamespace = nsURI; - throw new NanoXmlUtil.ParserStoppedException(); + throw ParserStoppedXmlException.INSTANCE; } public void addAttribute(final String key, final String nsPrefix, final String nsURI, final String value, final String type) throws Exception {